2012-10-10 58 views
0

我在那裏我用下面的代碼通過PHP來強制文件下載網站:PHP強制文件下載在Internet Explorer中失敗

$ZipData = file_get_contents($zipFilename); 
$ZipSize = filesize($zipFilename); 
header("Content-type: application/octet-stream"); 
header("Content-disposition: attachment; filename=".$ZipTitle.".zip"); 
echo $ZipData; 

雖然這完全在Chrome和Firefox,它根本沒有在Internet Explorer中。雖然谷歌搜索我找到了一個潛在的解決方案,並將代碼更改爲如下:

$ZipData = file_get_contents($zipFilename); 
$ZipSize = filesize($zipFilename); 
if (strstr($HTTP_USER_AGENT,"MSIE")){ 
    header("Pragma: public"); 
    header("Expires: 0"); 
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
    header("Content-type: application-download"); 
    header("Content-Length: $ZipSize"); 
    header("Content-disposition: attachment; filename=".$ZipTitle.".zip"); 
    header("Content-Transfer-Encoding: binary"); 
}else{ 
    header("Content-type: application/octet-stream"); 
    header("Content-disposition: attachment; filename=".$ZipTitle.".zip"); 
} 
echo $ZipData; 

但仍然沒有運氣。我不知道爲什麼它失敗了,也不知道從哪裏開始尋找錯誤或問題,這只是一些I.E.錯誤我不知道?我應該從哪裏開始嘗試尋找解決方案?

注意:$ ZipTitle將始終爲'TexturePacker_Pack_xxx',其中xxx是遞增的數字。 $ ZipFilename是一個現有的zip文件,該文件在文件發送到瀏覽器後被解除鏈接。

編輯:網站和有關的代碼都在行動上http://www.texturepacker.net

+0

你是哪裏定義的第二個解決方案'ZipSize'? –

+0

什麼版本的IE? – PenguinCoder

+0

下面的代碼Igniter的幫手,你應該嘗試'Content-Type:application/x-zip' – Touki

回答

0

Content-Length頭,似乎是不正確的。 PHP filesizeexpects a string並返回一個int。

更改它真正得到磁盤上的文件大小:

$zipFile = "C:\ZipFile.zip"; 
header("Content-Length: " . filesize($ZipFile)); 
+0

這正是它所設置的在代碼#2中與代碼#1相同)。 –

+0

根據代碼,這是目前用於$ ZipSize的內容。 – dux0r