PHP 图像上传器 - IE“pjpeg” MIME 类型,不起作用
我在使用图像上传脚本时遇到困难,难以在 Internet Explorer 中上传图像。我一直在 Google 中搜索解决方案,添加“image/pjpeg”mime 类型似乎对每个人都有效,但我已将其添加到我的代码中,但仍然无法使其工作。
这就是我的情况:
$acceptedExts = array ('jpg','jpeg');
if ( in_array($ext,$acceptedExts)
&& ( $_FILES["uploaded_file"]["type"] == "image/pjpeg"
|| $_FILES["uploaded_file"]["type"] == "image/jpeg")
&& ($_FILES["uploaded_file"]["size"] < 16000000)) {
我做错了什么吗?
谢谢!
I am having a hard time with my image upload script, getting the images to upload in Internet Explorer. I have been searching Google for a solution and adding the "image/pjpeg" mime type seemed to work for everyone, but I have added it to my code and still cannot get it to work.
Here is what I have:
$acceptedExts = array ('jpg','jpeg');
if ( in_array($ext,$acceptedExts)
&& ( $_FILES["uploaded_file"]["type"] == "image/pjpeg"
|| $_FILES["uploaded_file"]["type"] == "image/jpeg")
&& ($_FILES["uploaded_file"]["size"] < 16000000)) {
Am I doing anything wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
var_dump($_FILES['uploaded_file'])
来准确查看 IE 发送的内容。它可能是image/jpg
或完全不同的东西。但是,使用用户提供的['type']
字段进行验证是一种不好的形式。塑造这个价值是微不足道的。最好使用服务器端方法来确定文件类型,例如get_image_size()
或FileInfo
库,两者都返回文件的真实 mime 类型。Try a
var_dump($_FILES['uploaded_file'])
to see exactly what IE's sending. It may beimage/jpg
or something completely different. However, it's bad form to use the user-provided['type']
field for validation. It's trivial to forge that value. Better use a server-side method to figure out file type, such asget_image_size()
or theFileInfo
library, both of which return the true mime-type of the file.