我有一个可以上传/下载不同格式文件的应用程序。当我上传时,我有正确的 MIME 类型,但是当我下载相同的文件时,PHP 的 finfo_file 返回了错误的 MIME 类型。这是我得到的一些值:
代码:
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $filename);
echo $mime_type;
输出:
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
我检查了apache的mime.types文件,mime类型是正确的。我还需要做其他配置吗?有人可以帮我解决这个问题吗?
谢谢。
最佳答案
我这样做了,现在效果更好了:
代码:
$finfo = finfo_open(FILEINFO_MIME, "conf/magic");
$myMime = finfo_file($finfo, $filename);
无论如何,谢谢。
关于PHP - finfo_file 返回错误的 MIME 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36837875/