1

我能够在“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);

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

4

2 回答 2

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

Make sure $archive_file_name is just a name not a whole path, also it needs to be url encoded and should probably have a ".zip" extension at the end.

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

Why is the t in "type" lower cased?

于 2012-10-25T18:49:43.413 回答
0

You are overwriting some headers, some are needed just for IE, some for other browsers, IE is more picky.

Look at this link:

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

于 2012-10-25T19:05:32.710 回答