ダウンロードするファイルをブラウザが開くのを防ぐため、強制ダウンロードページを作成しようとしています。問題は、ダウンロードしたファイルが0バイトであり、したがって使用できないことです。私のコードで何が間違っていますか?強制的にPHPでダウンロードする
$file = "http://gh0stsec.zxq.net/background1.jpg";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($file));
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
header("Content-Description: File Transfer");
@readfile($file);
exit();
'application/force-download'は実際のMIMEタイプではありません。それは遅れている。それがダウンロードをトリガーするものではありません。それは 'Content-Dispositon'だけです。無効なMIMEタイプを追加することは無意味です。 – mario