0
這是我的問題。我正在嘗試使用標題下載文件。這裏是我的代碼:PHP強制下載不起作用
$content_type = mime_content_type('uploads/MyBBIntegrator_v1.3.1.zip');
$file = 'uploads/MyBBIntegrator_v1.3.1.zip';
header("Cache-Control: public");
header('Content-type: application/octet-stream');
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="MyBBIntegrator_v1.3.1.zip');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile('uploads/MyBBIntegrator_v1.3.1.zip');
然而,這樣做的唯一結果是,頁面顯示該文件的內容(這是一個文本文件)或奇怪符號的字符串,如果該文件是圖像/ ZIP/exe等
我該怎麼做才能解決這個問題?
刪除內容長度標題並嘗試.. – 2012-08-07 11:29:59
它爲我工作?哪個瀏覽器? – 2012-08-07 13:10:34
作爲開始,刪除所有不需要或未定義的響應頭字段(Content-Description,Content-Transfer-Encoding,Cache-Control:public ...) – 2012-08-13 08:17:36