[英]Checking image mime type in php unexpected error
Im trying to determine the mime type of an image: 我试图确定图像的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;
}
I use 我用
var_dump(determineImage($image));
this keep returning array(1) { [0]=> string(27) "Again cannot determine type" } 这会不断返回array(1){[0] => string(27)“再次无法确定类型”}
However this: 但是,这:
echo $image['type'];
just returns: 只是返回:
image/png
I've also got error_reporting(E_ALL) turned on. 我还打开了error_reporting(E_ALL)。 Can anyone make out what the problem is, have I made a silly mistake? 任何人都可以找出问题所在,我犯了一个愚蠢的错误吗?
the code is a total random (the check doesn't make sense at all) 该代码是完全随机的(检查根本没有意义)
by the way 顺便说说
if ($imageResource['type'] !== 'image/gif' AND
$imageResource['type'] !== 'image/jpeg' AND
$imageResource['type'] !== 'image/pjpeg' AND
$imageResource['type'] !== 'image/jpg' ...
AND not OR 与非或
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.