2011-04-08 98 views
0

我想強制下載。在IE中我得到一個錯誤,但在FF沒有問題文件下載力

header("Content-Type: application/force-download\n"); 
header("Content-Disposition: attachment; filename=test.txt"); 

echo 'test file'; 
+3

你得到哪些錯誤添加其他的頭? – Tobias 2011-04-08 11:44:41

+0

什麼'應用程序/強制下載'爲MIME類型?你從哪裏拿這個?! Oo – KingCrunch 2011-04-08 11:46:19

+0

該文件不可用 – clarkk 2011-04-08 11:48:49

回答

5

我只是用Google搜索你的好奇application/force-download MIME類型。我不知道,誰發明了這個,但看起來,它不存在。見http://mimeapplication.org/force-download.html

這意味着,IE可能不喜歡它。改爲使用application/octet-stream。據我記得firefox打開每個MIME類型的下載對話框,這是註冊與「顯示下載對話框」,或者它根本不知道。在這種情況下,FF可能不知道類型。

+0

它的工作原理,但現在我不能預設文件名... header(「Content-Type:application/octet-stream \ n」); header(「Content-Disposition:attachment; filename = test.txt」); – clarkk 2011-04-08 12:13:38

+0

不知道,如果這是你的行爲的原因,但不要在最後換行。 – KingCrunch 2011-04-08 18:13:35

0

這可以幫助你,我的作品

header('Content-Type: application/force-download'); 
header("Content-disposition: attachment; filename=$filename"); 
flush(); 
readfile($filename); 
exit; 

如果你願意可以:)

+0

在現代服務器代碼中,我們應該避免'應用程序/強制下載',這是一個老的黑客。 – 2015-02-04 14:09:09