简体   繁体   English

上传文件中的Mime类型错误

[英]Wrong Mime-type in uploaded file

I have form for file uploading in my website that i check mime-type of uploaded file to allow or refuse uploading it. 我在我的网站上有文件上传表格,我检查上传文件的mime类型以允许或拒绝上传。 It worked well until I've upgraded my firefox to 3.6.11 (in ubuntu). 在我将Firefox升级到3.6.11(在ubuntu中)之前,它一直运行良好。 But now uploading Doc files is not possible. 但现在无法上传Doc文件。 I checked the mime-type of file but it was 'application/x-php' instead of 'application/vnd.ms-word' or other msword mime-types. 我检查了mime类型的文件,但它是'application / x-php'而不是'application / vnd.ms-word'或其他msword mime-types。

I use 我用

echo $_FILES[$fileName]['type'];

to see the mime-type. 看哑剧类型。 I upload the same file from firefox 8 and firefox 3.6 and the output of above code was: 我从firefox 8和firefox 3.6上传相同的文件,上面代码的输出是:

FireFox 8: application/vnd.ms-word
FireFox 3.6: application/x-php

Is it a bug of firefox or I have to change my codes? 这是firefox的错误还是我必须更改代码?

I use PHP. 我用PHP。

$_FILES[...]['type'] is just arbitrary, user supplied, best-guess, unreliable (as you see) information supplied by the client which may or may not have anything to do with the actual file. $_FILES[...]['type']是任意的,用户提供的,最佳猜测的,客户端提供的不可靠(如您所见)的信息,与实际文件可能有或没有任何关系。 Never use it. 永远不要使用它。

Try to detect the MIME type yourself on the server. 尝试自己在服务器上检测MIME类型。 For example techniques, see How to get the content-type of a file in PHP? 有关示例技术,请参阅如何在PHP中获取文件的内容类型? .

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

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