我需要确定上传文件的类型
上传.xlsx
文件时,这段代码:
echo $_FILES['uploaded_file']['type']."<br>";
echo mime_content_type($_FILES['uploaded_file']['tmp_name']);
返回:
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/vnd.ms-excel
据我所知(从这里 PHP xls, xlsx, ppt, pptx headers ),application/vnd.ms-excel
不是 .xlsx
,而是 .xls
文件 mime 类型。
那么,为什么要为 .xlsx
文件返回 mime_content_type()
函数 application/vnd.ms-excel
?真相在哪里?
最佳答案
使用FileInfo而不是 mime_content_type (即 deprecated )。
关于 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
(在您的 linux 网络服务器中的/etc/mime.types 中可用)
关于php - 确定 excel 文件 mime 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16251955/