2012-10-25 28 views
1

我能夠在「chrome」和「FF」瀏覽器中使用PHP代碼壓縮文件夾並下載zip文件。但是當我在IE8中嘗試時,它會將下載的zip文件顯示爲未知類型的文件。我將不得不使用rar應用程序來打開它,但我希望將此zip文件直接下載爲IE8中的.zip文件,因爲它在其他瀏覽器中發生。以下是我用它的標題:在ie8中使用php下載zip文件

header("Pragma: public"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Cache-Control: public"); 
header("Content-Description: File Transfer"); 
header("Content-type: application/zip"); 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: ".filesize($archive_file_name)); 
header("Content-Disposition: attachment; filename=$archive_file_name"); 
readfile("$archive_file_name"); 
unlink($archive_file_name); 

有人可以讓我知道我需要更正代碼嗎?由於

回答

0
header("Content-Disposition: attachment; filename=$archive_file_name"); 

確保$ archive_file_name只是一個名字而不是整個路徑,還需要進行URL編碼,也許應該在結尾處對「.zip」擴展名。

header("Content-type: application/zip"); 

爲什麼「類型」中的t較低?

+0

是在$ archive_file_name僅僅是壓縮文件名,而不是路徑。我也將't'改爲'T',但它仍然不起作用。請告訴我,如果您需要更多關於這個 – user1489969

+0

@ user1489969的信息 - 請嘗試減少剛剛擁有的頭部數量,content-type和content-disposition標頭,並確保文件名是Url Encoded urlencode($ archive_file_name)。 –

+0

我剛剛通過只有以下幾行來嘗試:header(「Content-Disposition:attachment; filename = $ archive_file_name」); header(「Content-Type:application/zip」); readfile(「$ archive_file_name」); unlink($ archive_file_name);仍然沒有在IE8中工作。請讓我知道是否有其他需要的信息 – user1489969

0

您正在覆蓋一些標頭,有些只需要用於IE,一些用於其他瀏覽器,IE則更挑剔。

看看這個鏈接:

http://www.boutell.com/newfaq/creating/forcedownload.html

+0

感謝您的信息。我砍了幾個頭,只是:我只是通過只有以下幾行來嘗試:header(「Content-Disposition:attachment; filename = $ archive_file_name」);標題(「Content-Type:application/zip」); ReadFile的( 「$ archive_file_name」);取消鏈接($ archive_file_name);但它仍然沒有在IE8中工作。請讓我知道,如果有任何其他信息,你需要 – user1489969

+0

我的壞。這是我的錯,它沒有發生。我錯過了帶有文件名的擴展名「.zip」,所以這發生在IE8中。現在它的工作。 但是我嘗試了另一件事。我試圖在IE8中一次上傳多個文件。在chrome和FF中,它可以很好地與標記一起作爲。但現在用IE8。我認爲標籤不適用於IE8中的「多個」。如果有人知道如何在IE8上傳多個文件,請告訴我。 – user1489969