上传一份 wps 编辑过的 xlsx 文件,getMimeType 在不同服务器结果不一样?
public function test(Request $request)
{
$file = $request->file('file');
Log::info('xlsx mimetypes', [
$file->getMimeType(),
$file->getClientMimeType(),
$file->getClientOriginalExtension()
]);
}
本地 docker 容器打印日志:
[2022-04-27 19:02:47] development.INFO: xlsx mimetypes [“application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”,”application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”,”xlsx”]
服务器打印日志:
[2022-04-27 19:03:18] development.INFO: xlsx mimetypes [“application/zip”,”application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”,”xlsx”]
可以看出 getMimeType 在不同系统得到的结果不一样
我继续追踪代码,查看 getMimeType 的逻辑,在类文件FileBinaryMimeTypeGuesser
看到下面一段代码
passthru(“file -b –mime – %s”)
逻辑就是执行系统 file 命令来获取文件的 mime 信息
我尝试在本地和服务器分别执行 file -b --mime -- test.xlsx
得到的结果果然不一样:
Docker 容器:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=binary
服务器:application/zip; charset=binary
请教各位大佬有什么处理办法吗?
盲猜一下服务器上传的时候压缩了吧。。。