php “Content-Type:text/plain”强制下载文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7877140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Content-Type:text/plain" forces to download the file
提问by o0'.
If I call header('Content-Type:text/plain; charset=ISO-8859-15');
the browser will download the file instead of showing it. Using text/html
works instead. (the downloaded file is processed anyway, it's not downloading the source code)
如果我调用header('Content-Type:text/plain; charset=ISO-8859-15');
浏览器将下载文件而不是显示它。使用text/html
作品代替。(下载的文件无论如何处理,不是下载源代码)
I've tried to add header('Content-Disposition:inline;');
but it was just ignored.
我试图添加,header('Content-Disposition:inline;');
但它只是被忽略了。
I'm pretty clueless about what could cause this problem, any tip?
我对可能导致此问题的原因一无所知,有什么提示吗?
The server is MAMP 1.9.6 (PHP 5.3.5, Apache/2.0.64).
服务器是 MAMP 1.9.6(PHP 5.3.5,Apache/2.0.64)。
edit: this only happens on Chrome, it works on Firefox, Camino and Safari.
编辑:这只发生在 Chrome 上,它适用于 Firefox、Camino 和 Safari。
回答by DaveRandom
I cannot reproduce this with this script:
我无法使用此脚本重现此内容:
<?php
header('Content-Type:text/plain; charset=ISO-8859-15');
echo "This is some text";
However, I can reproduce it with this:
但是,我可以用这个重现它:
<?php
header('Content-Type:text/plain; charset=ISO-8859-15');
echo "\x00This is some text";
Make sure that your content actually isplain ASCII text...
确保您的内容实际上是纯 ASCII 文本...
回答by Олег Всильдеревьев
For me this works:
对我来说这有效:
header('Content-Type:text/javascript;');