获取微软10边缘浏览器MIME类型的PHP(Getting Microsoft 10 Edge browser Mime Types php)

编程入门 行业动态 更新时间:2024-10-06 09:25:46
获取微软10边缘浏览器MIME类型的PHP(Getting Microsoft 10 Edge browser Mime Types php)

在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-stream

Apparently 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.

更多推荐

本文发布于:2023-07-19 15:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1182584.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:微软   边缘   浏览器   类型   MIME

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!