在PHP中强制文件下载会破坏zip文件

时间:2015-08-20 23:54:02

标签: php download

我的PHP脚本强制下载文件,一切正常,但在强制下载zip文件时,它们会损坏。

当我尝试在本地打开zip文件时,它只是从.zip转换为.zip.cpgz

如果我从直接URL下载文件,那么zip文件就可以了,所以我知道它只是在推送/下载阶段发生了腐败。

这是我的代码

    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"_zip_download.zip\"");
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-Description: File Transfer");
    header("Content-Length: " . filesize($zip_file));

1 个答案:

答案 0 :(得分:1)

对于zip文件,您可以设置header("Content-Type: application/zip");

header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"_zip_download.zip\"");
header("Content-Length: " . filesize($zip_file));
readfile($zip_file);
exit;
相关问题