dongsiju1941 2010-03-18 23:07
浏览 41
已采纳

甚至PHP也有IE的“漏洞”

This is not a real bug BUT for sure it is not what you would expect. I have this sample code to upload images:

if($type=="image/jpg" || $type=="image/jpeg" || $type=="image/pjpeg" || $type=="image/tiff" || $type=="image/gif" || $type=="image/png") {
   // make upload
else echo "Incorrect format ...."; 

The problem is that if I modify the extension of an image, let's say to .jpgq or even .jpg% and I try to upload it, FF and Chrome will say that the file"s type is "application/octet-stream" and normally the condition will be false.

IE, on the other hand, will say that the file's type is "image/jpeg", the condition will be true and the file will be uploaded. Of course, any browser trying to read the image later will not be able to do so.

It is not a bug because on msdn.microsoft.com it says that: "If the "suggested" (server-provided) MIME type is unknown (not known and not ambiguous), FindMimeFromData immediately returns this MIME type" and "If the server-provided MIME type is either known or ambiguous, the buffer is scanned in an attempt to verify or obtain a MIME type from the actual content."

My questions are:

  1. Why does IE / the server knows the real MIME type on upload BUT it will fail to read it from the server?
  2. How can I work around this issue (if the file doesn't have the right extension, the condition has to be false)? Is it wise to check the extension format (and not the MIME type)?
  3. is any of the above extensions not recomended to use? Should I add others?
  • 写回答

2条回答 默认 最新

  • dongyi1215 2010-03-18 23:09
    关注

    Forget checking the mime type. Use getimagesize() instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。