我正在嘗試創建一個強制下載頁面,以防止瀏覽器打開應該下載的文件。問題是下載的文件有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();
'應用程序/強制下載'是不是一個真正的MIME類型。它被推遲了。這不是觸發下載的原因。它只是'Content-Dispositon'。添加無效的MIME類型毫無意義。 – mario 2012-02-19 15:21:00