Php ZipArchive下载失败

Php ZipArchive下载失败,php,ziparchive,php-zip-archive,Php,Ziparchive,Php Zip Archive,我正在使用ZipArchive类生成并下载zipFile。它必须在PHP5.2.14上运行。 它在php 5.3.x上完美地工作,代码如下: $filename = "test.zip"; $zip = new ZipArchive(); $opened = $zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE); $zip->addFromString(...,...); $zip->close()

我正在使用ZipArchive类生成并下载zipFile。它必须在PHP5.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文件


解决方案?

我正在发布一部分使用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的权限吗?

添加描述zip文件大小(以字节为单位)的内容长度标题。此外,请检查在打开之前是否绝对没有空格