我能够在“chrome”和“FF”浏览器中使用PHP代码压缩文件夹并下载zip文件 . 但是当我在IE8中尝试它时,它将下载的zip文件显示为未知类型的文件 . 我将不得不专门用rar应用程序打开它,但我希望将此zip文件直接下载为IE8中的.zip文件,就像在其他浏览器中一样 . 以下是我用于它的 Headers :
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);
有人可以让我知道我需要更正代码的位置吗?谢谢
2 回答
确保$ archive_file_name只是一个名称而不是一个完整的路径,它也需要进行url编码,并且最后应该有一个“.zip”扩展名 .
为什么“类型”中的t更低?
你正在覆盖一些 Headers ,一些仅用于IE,一些用于其他浏览器,IE更挑剔 .
看看这个链接:
http://www.boutell.com/newfaq/creating/forcedownload.html