我正在尝试检查上传的图片是PNG,JPG还是GIF,而不只是检查文件扩展名。我正在尝试以下方法:
$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
但即使是图像,我也会收到提醒。谁能指出我为什么?
答案 0 :(得分:1)
应该是:
$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 ' );
}