“Content-Type:text/plain” forces to download the file

江枫思渺然 提交于 2019-12-22 04:43:27

问题


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.


回答1:


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




回答2:


For me this works:

header('Content-Type:text/javascript;');


来源:https://stackoverflow.com/questions/7877140/content-typetext-plain-forces-to-download-the-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!