[英]PHP Force download not working
這是我的問題。 我正在嘗試使用標題下載文件。 這是我的代碼:
$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');
但是,這樣做的唯一結果是頁面顯示文件的內容(它是一個文本文件),或者如果文件是image / zip / exe等,則顯示一串奇怪的符號。
我該怎么做才能解決這個問題?
首先,不建議使用mime_content_type()
,您應該嘗試另一種方法來獲取MIME值。
我已經檢查了您的代碼,它在我的服務器上正常工作,並且對我來說正常工作。 您應檢查可能阻止下載的INI指令。 嘗試全新安裝服務器。
另外,在您將片段插入問題之前,腳本不會產生任何輸出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.