用作一般用途的MIME类型是什么? [英] What MIME-type to use as general purpose?

查看:78
本文介绍了用作一般用途的MIME类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,可用来下载不同类型的文件(PDF,JPEG,RAR等).效果很好,但是我注意到那里的MIME类型存在问题.

I have a PHP script that I use to download different types of files (PDF, JPEG, RAR end other). Works great, however I noticed an issue there with the MIME-type.

是否存在可以安全地用于一般用途"的通用MIME类型?我正在考虑所有文件类型的application/octet-stream.

Is there a universal MIME-type I can safely use for "general purpose"? I am thinking of application/octet-stream for all file types.

还是应该为每种文件类型分别进行MIME处理?

Or should I do the MIME for each file type individually?

应该可以下载文件,直接在应用程序中打开文件并不重要.

It's supposed to deliver downloads, it's not important to open the files in apps directly.

推荐答案

如果您只想传送文件,而不关心打开它所需的应用程序类型,那么可以安全地将文件mime类型指定为application/octet-stream.但是,您应该指定应保存它,并且不应尝试在浏览器中内联打开它.

If you just want to deliver files and don't care about the type of application needed to open it, then it's safe to specify the file mime type as application/octet-stream. However you should specify that it should be saved and should not be attempted to be opened inline within the browser.

您应将标题指定为: Content-Type: application/octet-stream Content-Disposition: attachment; filename="file.png"

you should specify the header as: Content-Type: application/octet-stream Content-Disposition: attachment; filename="file.png"

它通知浏览器(或客户端应用程序)应下载文件,而不应尝试以内联方式打开文件.

It informs the browser (or the client application) that the file should be downloaded and should not be attempted to be opened inline.

这篇关于用作一般用途的MIME类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆