>  기사  >  백엔드 개발  >  PHP输出文件头异常

PHP输出文件头异常

WBOY
WBOY원래의
2016-06-13 13:37:571036검색

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');不知道写错了没?
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.