If a file is uploaded to the server, is there a way using PHP, to make sure that it's actually a picture and not just a file with a .jpg or .gif extension?
Check file is image or not in php This function will return true or false on the basis of the extension of files. It provides true if the file is an image or returns false if the file is not an image. You can pass more image file extensions to $imgExtArr variable.
Image validation occurs in Gateway Server image processing threads. Image Compliance collects the validation data so it can apply the specified set of image validation rules, which allows a rule set to execute the same image test using different threshold criteria.
The imagetypes() function is an inbuilt function in PHP which is used to return the image types supported by the PHP inbuilt installed library. Parameters: This function does not accept any parameter.
Using (part) of the GD library.
PHP: GD - Manual
array getimagesize ( string $filename [, array &$imageinfo ] )
The first element of the array will be 0 if there is no image. PHP: getimagesize
If you don't have GD installed (most of the time you will), you can read the file header as Shane mentioned.
EDIT: Actually, as Neal pointed out in the comments, the GD library is not even required to use this function. So use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With