阻止IE8打开或下载text / plain MIME类型 [英] Stop IE8 from opening or downloading a text/plain MIME type

查看:200
本文介绍了阻止IE8打开或下载text / plain MIME类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP中动态生成文本文件,因此它具有.php扩展名,但是文本/纯MIME类型。除IE8外,所有浏览器都将文件显示为格式良好的预格式化文本。

I'm dynamically generating a text file in PHP, so it has a .php extension but a text/plain MIME type. All browsers display the file as nicely preformatted text, except IE8.

谷歌搜索告诉我,如果HTTP标头内容类型与预期的内容类型不匹配,我们已经添加了安全性(我认为基于扩展和一些嗅探)然后它强制下载文件。在我的情况下,我必须打开它,并允许打开我刚刚告诉它打开的文件!这可能是Win7的烦恼。当然,提供静态纯文本文件工作正常。

Googling tells me that they've added security where if the HTTP header content type doesn't match the expected content type (I think based on the extension and some sniffing) then it forces the file to be downloaded. In my case I have to open it, and also give it permission to open the file I just told it open! That's probably a Win7 annoyance though. Serving a static plain text file works fine, of course.

那么我可以阻止IE8下载文件并让它正常查看吗?代码必须在多个共享托管环境中运行,所以我认为我坚持使用.php扩展名。

So can I stop IE8 from downloading the file and get it to view it normally? The code has to run on multiple shared hosting environments, so I think I'm stuck with the .php extension.

推荐答案

添加这到您的HTTP标头:

Add this to your HTTP header:

X-Content-Type-Options: nosniff

这是一个IE8功能,可以选择退出其MIME嗅探。

It's an IE8 feature to opt-out of its MIME-sniffing.

来源

这篇关于阻止IE8打开或下载text / plain MIME类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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