简体   繁体   中英

zip file download using php in ie8

I was able to zip a folder and download the zip file using PHP code in "chrome" and "FF" browsers. But when I try that in IE8 it shows the downloaded zip file as a file of unknown type. I will have to open it with rar application specifically but I am looking to make this zip file download directly as .zip file in IE8 as it is happening in the other browsers. The following are the headers I used for it:

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);

Can someone please let me know where I need to correct the code? Thanks

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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