I am trying to check that an uploaded image is a PNG, JPG or GIF and not just check the file extension. I am trying the following:
$allowed_types = array (IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);
$detectedType = exif_imagetype($_FILES['file_to_upload']['tmp_name']);
if ( !in_array($detectedType, $allowed_types) ) {
die ( 'Please upload a pdf or an image ' );
}
//code to handle image
However I am receiving an alert even if it is an image. Can anyone point me towards why?
should have been:
$allowed_types = array (IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);
$detectedType = exif_imagetype($_FILES['file']['tmp_name']);
if ( !in_array($detectedType, $allowed_types) ) {
die ( 'Please upload a pdf or an image ' );
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.