简体   繁体   English

PHP - finfo_file 返回错误的 MIME 类型

[英]PHP - finfo_file returns incorrect MIME type

I have an application which i can upload/download files with different format.我有一个应用程序,我可以上传/下载不同格式的文件。 When i upload i have the correct MIME type, but when i download the same file, finfo_file of PHP returns me an incorrect MIME type.当我上传时,我有正确的 MIME 类型,但是当我下载相同的文件时,PHP 的 finfo_file 返回一个不正确的 MIME 类型。 Here is some values that i got :这是我得到的一些值:

Code :代码 :

$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $filename);
echo $mime_type;

Output :输出 :

application/msword // test0.pot INCORRECT should be application/vnd.ms-powerpoint
text/plain // test1.csv ICNORRECT should be text/csv
application/vnd.ms-powerpoint // test2.pptx INCORRECT should be application/vnd.openxmlformats-officedocument.presentationml.presentation
application/msword // test3.pps INCORRECT should be application/vnd.ms-powerpoint
application/msword // test4.docx INCORRECT should be application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/msword // test5.doc CORRECT
application/vnd.ms-excel // test6.xls CORRECT
application/vnd.ms-excel // test7.xlsx INCORRECT should be application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/msword // test8.docm INCORRECT should be application/vnd.ms-word.document.macroenabled.12
application/pdf // test9.pdf CORRECT

I checked apache's mime.types file, mime types are correct.我检查了 apache 的 mime.types 文件,mime 类型是正确的。 Is there an another configuration that i have to do ?我还需要做其他配置吗? Can someone help me to fix this ?有人可以帮我解决这个问题吗?

Thanks.谢谢。

I did this and it works better now :我这样做了,现在效果更好了:

Code :代码 :

$finfo = finfo_open(FILEINFO_MIME, "conf/magic");
$myMime = finfo_file($finfo, $filename);

Thanks anyway.不管怎么说,还是要谢谢你。

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

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