Possible Duplicate:
GetImageSize() not returning FALSE when it should
i currently have a filter system as follows:
// Check to see if the type of file uploaded is a valid image type
function is_valid_type($file)
{
// This is an array that holds all the valid image MIME types
$valid_types = array("image/jpg", "image/JPG", "image/jpeg", "image/bmp", "image/gif", "image/png");
if (in_array($file['type'], $valid_types))
return 1;
return 0;
}
but i have been told that it is better to check the filetype myself, how would i use the getimagesize() to check the filetype in a similar way?
getimagesize()
returns an array with 7 elements. The index 2 of the array contains one of the IMAGETYPE_XXX
constants indicating the type of the image.
The equivalent of the function provided using getimagesize() would be
function is_valid_type($file)
{
$size = getimagesize($file);
if(!$size) {
return 0;
}
$valid_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP);
if(in_array($size[2], $valid_types)) {
return 1;
} else {
return 0;
}
}
You can use as below
$img_info = getimagesize($_FILES['image']['tmp_name']);
$mime = $img_info['mime']; // mime-type as string for ex. "image/jpeg" etc.
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