我试图确定图像的 mime 类型:
$image = $_FILES['image']; //code shortened
function determineImage($imageResource){
$errors = array();
$types = array('gif' => IMAGETYPE_GIF,
'jpeg' => IMAGETYPE_JPEG,
'png' => IMAGETYPE_PNG,
'bmp' => IMAGETYPE_BMP);
if ( !in_array(exif_imagetype($imageResource['tmp_name']), $types )) {
$errors[] = 'Cannot determine mime type';
}
if ($imageResource['type'] !== 'image/gif' ||
$imageResource['type'] !== 'image/jpeg' ||
$imageResource['type'] !== 'image/pjpeg' ||
$imageResource['type'] !== 'image/png'){
$errors[] = 'Again cannot determine type';
}
return $errors;
}
我用
var_dump(determineImage($image));
这不断返回数组(1){[0]=>字符串(27)“再次无法确定类型”}
然而这:
echo $image['type'];
只是返回:
image/png
我还打开了 error_reporting(E_ALL) 。谁能弄清楚问题是什么,我犯了一个愚蠢的错误吗?