繁体   English   中英

在ie8中使用php下载zip文件

[英]zip file download using php in ie8

我能够在“ chrome”和“ FF”浏览器中使用PHP代码压缩文件夹并下载zip文件。 但是,当我尝试在IE8中将下载的zip文件显示为未知类型的文件时。 我将不得不专门使用rar应用程序打开它,但我希望将此zip文件直接下载为IE8中的.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);

有人可以让我知道我需要在哪里更正代码吗? 谢谢

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

确保$ archive_file_name只是一个名称,而不是完整路径,还需要对其进行url编码,并且末尾可能应带有“ .zip”扩展名。

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

为什么“类型”中的t小写?

您正在覆盖某些标头,某些标头仅用于IE,某些标头用于其他浏览器,IE更挑剔。

查看此链接:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM