我在那里我用下面的代码通过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