确定excel文件的mime类型

OTA*_*TAR 4 php excel mime-types

我需要确定什么是上传文件的类型

上传.xlsx文件时,此代码:

 echo $_FILES['uploaded_file']['type']."<br>";  
 echo mime_content_type($_FILES['uploaded_file']['tmp_name']);
Run Code Online (Sandbox Code Playgroud)

收益:

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/vnd.ms-excel
Run Code Online (Sandbox Code Playgroud)

据我所知(从这里PHP xls,xlsx,ppt,pptx标题),application/vnd.ms-excel不是.xlsx,但.xls文件mime类型.

那么,为什么返回mime_content_type()功能application/vnd.ms-excel.xlsx文件?真相在哪里?

tuc*_*uxi 8

使用FileInfo而不是mime_content_type(不推荐使用).

关于mime类型和扩展,

application/vnd.ms-excel                                          xls xlb xlt
application/vnd.ms-excel.addin.macroEnabled.12                    xlam
application/vnd.ms-excel.sheet.binary.macroEnabled.12             xlsb
application/vnd.ms-excel.sheet.macroEnabled.12                    xlsm
application/vnd.ms-excel.template.macroEnabled.12                 xltm
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
Run Code Online (Sandbox Code Playgroud)

(可从linux webserver中的/etc/mime.types获得)


Mar*_*ker 5

mime_content_type()不是特别准确,并且已被弃用,取而代之的是Fileinfo() 的 mime_content_type;尽管就个人而言,我打开文件并显式测试文件中可能不包含在 mime_magic 签名详细信息中的某些数据元素