在Microsoft 10的Edge浏览器中检查文件MIME类型的文件时,我得到了这个Mime类型的.doc文件:
application/octet-stream显然这表明“任意二进制数据”: 我是否需要Content-Type:application / octet-stream用于文件下载?
在其他浏览器上,我得到application/msword
有没有新的方式处理MIME类型的边缘浏览器的.doc文件,也可能是我需要注意的其他MIME类型?
更新:
我使用php的$_FILES['uploadName']['type']来抓取MIME类型
When checking the file mime types of files being uploaded in Microsoft 10's Edge browser, I get this Mime Type for .doc files:
application/octet-streamApparently this indicates "arbitrary binary data": Do I need Content-Type: application/octet-stream for file download?
On other browsers I get application/msword
Is there a new way mime types are handled for .doc files for the Edge browser, and maybe other mime types I need to be aware of?
Update:
I was grabbing the mime type using php's $_FILES['uploadName']['type']
最满意答案
我发现通过使用这个,我得到了正确的mime类型:
$finfo = new finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->file($_FILES['uploadName']['tmp_name'][$key]);正如马丁在上面的评论中提到的那样:
您不应该从$ _FILE中提供的数据中获取MIME类型,因为这非常脆弱,并且无法解释,正如您所遇到的。 相反,请对上传的临时文件,使用finfo()或类似文件进行新的分析。
I found that by using this instead, I get the correct mime type:
$finfo = new finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->file($_FILES['uploadName']['tmp_name'][$key]);And as Martin mentioned in a comment above:
You should not grab the MIME type from the data given in $_FILE as this is extremely flaky and up for interpretation, as you are experiencing. Instead, do a new analysis of the uploaded temporary file, Use finfo() or similar.
更多推荐
发布评论