ホームページ >バックエンド開発 >PHPチュートリアル >PHP 出力ファイルのヘッダー例外
PHP 出力ファイルのヘッダー エラー
ローカルの nginx 1.09 テストではすべてが正常ですが、サーバー nginx 1.12 にアップロードすると、テキスト出力 を選択するとエラーが報告されます
完全なコード:
<!-- 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].'树'; ?>