我在那裏我用下面的代碼通過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
你是哪裏定義的第二個解決方案'ZipSize'? –
什麼版本的IE? – PenguinCoder
下面的代碼Igniter的幫手,你應該嘗試'Content-Type:application/x-zip' – Touki