我使用ZipArchive类生成和下载zipFile。它必须在php 5.2.14上工作。它在php 5.3.x上运行得很好,代码如下:
$filename = "test.zip";
$zip = new ZipArchive();
$opened = $zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
$zip->addFromString(...,...);
$zip->close();
header('Content-disposition: attachment; filename='.$filename);
header('Content-type: application/zip');
readfile("$filename");
exit();在php5.2.14上,它生成一个空的(0字节大小) zip文件。如果删除exit()指令,它将生成一个损坏的zip文件。
解决办法?
发布于 2015-10-22 10:03:01
我正在发布我的程序中使用ZipArchive类的一部分
$this->licensePlate = "AA000AA";
$this->fileName = "path/to/file/tmp.zip";
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="Foto_'.$this->licensePlate.'.zip"');
readfile($this->fileName);您确定确实要将这些文件添加到ZipArchive中吗?您确定您确实拥有创建ZipArchive的权限吗?
https://stackoverflow.com/questions/33278162
复制相似问题