简体   繁体   English

Internet Explorer文件上传无法通过MIME类型检查

[英]Internet Explorer file upload fails mime-type check

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). 我创建的表单允许用户在字段中提交他们的数据,以及图像附件(验证:.EPS或.JPG格式)。

The script works fine in Firefox and Safari, but not in Internet Explorer. 该脚本在Firefox和Safari中可以正常运行,但在Internet Explorer中不能正常运行。 In IE, whether or not you attach an image of the correct type, it returns the error for incorrect file type. 在IE中,无论您是否附加了正确类型的图像,它都会针对错误的文件类型返回错误。 So for some reason it seems IE is not validating the file type as the PHP is asking it to do. 因此出于某种原因,IE似乎没有像PHP要求的那样验证文件类型。

<?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. 如果需要任何说明,请告诉我。

http://www.php.net/manual/en/features.file-upload.php#75932 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 理查德·戴维(Richard Davey)富有,来自corephp dot co dot uk 2007年6月22日12:05
[...] you may be inclined to validate an update based on its reported mime-type from the $_FILES array. 您可能倾向于根据$ _FILES数组中报告的mime类型来验证更新。 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?!) 但是请注意这一点-它是由浏览器设置的,而不是由PHP或Web服务器设置的,并且浏览器不一致(有什么新功能?!)

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. IE将为附件发送自己的mime-type (基于其文件系统关联),该类型通常可能与您在代码中期望的不同。 This data can also be spoofed, so it's best not to trust what the browser says about the file's mime-type . 这些数据也可以被欺骗,因此最好不要相信浏览器对文件的mime-type所说的话。

Also: 也:

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

keith at phpdiary dot org 24-May-2005 11:14 keith在phpdiary dot org上2005年5月24日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. [...]我最好的选择是让您检查文件的扩展名,并使用exif_imagetype()检查有效图像。 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. 许多人建议使用getimagesize()(如果文件确实是图像,则返回数组),否则返回false,但是exif_imagetype()更快。 (the manual says it so) (手册中是这样说的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM