私はUbuntuの/ tmpフォルダからzipファイルをダウンロードしようとしています。しかし、私はPHPコードを実行すると、ダウンロードボックスを表示する代わりに、ブラウザにガベージテキストが表示されます。私はシンプルなテキストファイルを試してみましたが、私にダウンロードダイアログボックスを表示する代わりに、その内容をブラウザに表示しました。なぜこの強制ダウンロードが機能しないのか以下はコードです。php force downloadは画面にゴミを表示します
if (file_exists($dir.$filename)) {
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($dir.$filename));
header('Content-disposition: attachment; filename='.basename($dir.$filename));
readfile($dir.$filename);
exit(0);
}
`
**可能な解決策:http://stackoverflow.com/questions/15123809/force-download-only-displays-in-browser-doesnt-prompt-for-download#answer-22228190** – gibberish