Home >Backend Development >PHP Tutorial >PHP输出文件头异常

PHP输出文件头异常

WBOY
WBOYOriginal
2016-06-13 10:07:12916browse

PHP输出文件头错误
本地 nginx 1.09 测试一切正常,上传到服务器 nginx 1.12, 在选择文本输出时就报错
完整代码:

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php @$id=$_GET['id']?$_GET['id']:'a';    @$txt=$_GET['txt']?$_GET['txt']:'';    $trees=array();    $trees["a"]="苹果";    $trees["b"]="香蕉";    $trees[3]="樱桃";if($txt){    header('Content-Disposition: attachment; filename="'.$trees[$id].'.txt"');    header('Content-type: text/'.($txt?'plain':'html').'; charset=utf-8');    echo '您选择种了:'.$trees[$id].'树';    die();}else{    echo '<h3>您选择种了:'.$trees[$id].'树';?>
选择您想种的树:
输出格式:

演示地址: http://guilyn.host.org/cn/demo/full.php

------解决方案--------------------
应该是BOM头的原因。 可以修改下php.ini output_buffering=On,或者去掉它
------解决方案--------------------
保存为utf8的时候就需要注意这个头的事情 ...
------解决方案--------------------
int_set('output_buffering=On');不知道写错了没?
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn