exif_imagetype
When an image is uploaded through a form, its size, type, etc are provided for us as part of the $_FILE associative array, but how do you check the type of an image on the local machine or across a network? The exif_imagetype function is the answer.
This function determines the header type of an image file. There are numerous constants such as IMAGETYPE_GIF, IMAGETYPE_BMP, etc that can be used to determine the type of the image. It’s function looks like this:
int|false exif_imagetype ( string filename)
The exif_imagetype function is part of the GD image library, so you must have this library installed for the exif_imagetype function to work. Here’s some code to check whether the function exists and then to output the type of a GIF image file:
<?php
if(function_exists(”exif_imagetype”))
echo exif_imagetype(”/pics/bounty.gif”);
else
echo “You don’t have the GD image library installed”;
?>
