"内容类型:文本/无格式"强制下载文件 [英] "Content-Type:text/plain" forces to download the file

查看:146
本文介绍了"内容类型:文本/无格式"强制下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我调用 header('Content-Type:text / plain; charset = ISO-8859-15'); 浏览器将下载文件而不是显示它。使用 text / html 来代替。 (无论如何处理下载的文件,它不会下载源代码)



我试着添加头('Content-Disposition:inline ;'); 但它被忽略。



我对于可能导致此问题的任何提示非常无知?



服务器是MAMP 1.9.6(PHP 5.3.5,Apache / 2.0.64)。

编辑:this只能在Chrome上发生,它可以在Firefox,Camino和Safari上运行。 我不能用这个脚本重现这一点:

>'

 <?php 

header('Content-Type:text / plain; charset = ISO-8859- 15' );
回声这是一些文字;

然而,我可以用它重现它:

 <?php 

header('Content-Type:text / plain; charset = ISO-8859-15');
echo\x00This是一些文字;

确保您的内容实际上是纯文本的ASCII文本...


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)

I've tried to add header('Content-Disposition:inline;'); but it was just ignored.

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

edit: this only happens on Chrome, it works on Firefox, Camino and Safari.

解决方案

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 is plain ASCII text...

这篇关于&QUOT;内容类型:文本/无格式&QUOT;强制下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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