2016-04-25 169 views
1

我有一个应用程序,我可以上传/下载不同格式的文件。当我上传我有正确的MIME类型,但是当我下载相同的文件时,PHP的finfo_file返回给我一个不正确的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类型是正确的。是否有另一种配置,我必须做的?有人可以帮我解决这个问题吗?

谢谢。

+1

FWIW,有些格式不能与其他格式区分开来。 CSV也是一个完全有效的“文本/纯文本”,没有技术上的差异。 *根据定义,检测*类型是不准确的科学。 – deceze

+0

当我下载一个.csv文件时,用Bloc笔记打开它并不符合人体工程学。默认情况下,所选的应用程序必须是Excel才能读取它,并且对于PowerPoint演示文稿,它应该是ms PowerPoint不是ms字。我的意思是,那就是我想要的。 – cglvli

回答

1

我这样做,它现在更好的工作:

代码:

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

还是要谢谢你。