PHP - finfo_file 返回错误的 MIME 类型

标签 php mime-types

我有一个可以上传/下载不同格式文件的应用程序。当我上传时,我有正确的 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/

相关文章:

javascript - 如何从 base64 字符串获取 MIME 类型?

php - Cakephp 3.0.3 如何使用默认布局?

android - 获取打开文件的默认应用程序的图标

jquery - 服务器上的音频文件以 splinter 的方式嵌入

php - 如何检查图像完整性?

PHP mime 类型标准化

php - MySQL 后续数字

php - 按 Yii2 RESTful API 上的其他字段过滤

php - 如何仅从 CSV 文件数组中获取唯一值

PHP 从数组中添加一个项目