dp13668681869 2011-04-15 22:35
浏览 76
已采纳

Internet Explorer文件上载失败mime-type检查

I have cobbled together some scripts from various internet sources to get a form working. I have run into an issue that I can't solve. The form I created allows the user to submit their data in fields, plus an image attachment (validation: .EPS or .JPG format).

The script works fine in Firefox and Safari, but not in Internet Explorer. In IE, whether or not you attach an image of the correct type, it returns the error for incorrect file type. So for some reason it seems IE is not validating the file type as the PHP is asking it to do.

<?php
/* ....
   snip
   .... */
      $filetype=$_FILES["prosp_client_logo"]["type"];
/* ....
   snip
   .... */
      elseif($filetype=="application/postscript" or $filetype=="image/jpg" or $filetype=="image/jpeg") {
/* ....
   snip
   .... */
?>

Please let me know if you need any clarification.

  • 写回答

1条回答 默认 最新

  • douying3251 2011-04-15 22:40
    关注

    http://www.php.net/manual/en/features.file-upload.php#75932

    Richard Davey rich at corephp dot co dot uk 22-Jun-2007 12:05
    [...] you may be inclined to validate an update based on its reported mime-type from the $_FILES array. However be careful with this - it is set by the browser, not by PHP or the web server, and browsers are not consistent (what's new?!)

    IE will send its own mime-type (based on its filesystem association) for the attachment, which can often be different than what you're expecting in your code. This data can also be spoofed, so it's best not to trust what the browser says about the file's mime-type.

    Also:

    http://www.php.net/manual/en/features.file-upload.php#53133

    keith at phpdiary dot org 24-May-2005 11:14
    [...] My best bet would be for you to check the extension of the file and using exif_imagetype() to check for valid images. Many people have suggested the use of getimagesize() which returns an array if the file is indeed an image and false otherwise, but exif_imagetype() is much faster. (the manual says it so)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?