PHP:exif_imagetype() 不起作用?
我有这个扩展检查器:
$upload_name = "file";
$max_file_size_in_bytes = 8388608;
$extension_whitelist = array("jpg", "gif", "png", "jpeg");
/* checking extensions */
$path_info = pathinfo($_FILES[$upload_name]['name']);
$file_extension = $path_info["extension"];
$is_valid_extension = false;
foreach ($extension_whitelist as $extension) {
if (strcasecmp($file_extension, $extension) == 0) {
$is_valid_extension = true;
break;
}
}
if (!$is_valid_extension) {
echo "{";
echo "error: 'ext not allowed!'\n";
echo "}";
exit(0);
}
然后我添加了这个:
if (exif_imagetype($_FILES[$upload_name]['name']) != IMAGETYPE_GIF
OR exif_imagetype($_FILES[$upload_name]['name']) != IMAGETYPE_JPEG
OR exif_imagetype($_FILES[$upload_name]['name']) != IMAGETYPE_PNG) {
echo "{";
echo "error: 'This is no photo..'\n";
echo "}";
exit(0);
}
当我将其添加到我的图像上传功能时,该功能就停止工作。我没有收到任何错误,甚至连我自己犯的“这不是照片”都没有,可能是哪里出了问题?
刚刚和我的主人核实过。他们支持函数 exif_imagetype()
I have this extension checker:
$upload_name = "file";
$max_file_size_in_bytes = 8388608;
$extension_whitelist = array("jpg", "gif", "png", "jpeg");
/* checking extensions */
$path_info = pathinfo($_FILES[$upload_name]['name']);
$file_extension = $path_info["extension"];
$is_valid_extension = false;
foreach ($extension_whitelist as $extension) {
if (strcasecmp($file_extension, $extension) == 0) {
$is_valid_extension = true;
break;
}
}
if (!$is_valid_extension) {
echo "{";
echo "error: 'ext not allowed!'\n";
echo "}";
exit(0);
}
And then i added this:
if (exif_imagetype($_FILES[$upload_name]['name']) != IMAGETYPE_GIF
OR exif_imagetype($_FILES[$upload_name]['name']) != IMAGETYPE_JPEG
OR exif_imagetype($_FILES[$upload_name]['name']) != IMAGETYPE_PNG) {
echo "{";
echo "error: 'This is no photo..'\n";
echo "}";
exit(0);
}
As soon when I added this to my imageupload function, the function stops working. I dont get any errors, not even the one i made myself "this is no photo", what could be wrong?
Just checked with my host. They support the function exif_imagetype()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是开关用法的示例:
您的脚本也可以使用,但您必须在条件之间放置 AND:
Here is the example with the switch usage:
Your script can be used too, but you have to put AND between conditions:
有一种更好、更短的方法来获取图像类型,我目前正在使用它(无法确定它是否有效,因为 PHP.net 中没有记录它,因为 image_type_to_mime_type() 也可以将整数作为输入):
There's a better, shorter way to get image types, which I'm currently using (can't be sure if it will works as it is not documented in PHP.net as image_type_to_mime_type() can also take an integer as input):
你可以这样使用。希望这会有所帮助
You can use like that. Hope this is will be helpful