可能重复:
How to zip a whole folder using PHP
嗨,我正在使用zipArchive在php.The压缩文件中创建一个zip文件夹,其中包含一个文件夹(其中包含一个文件)和一个文件。我使用以下代码下载压缩文件:
$file_path = "zip/test.zip";
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=download.zip');
header('Content-Length: ' . filesize( $file_path));
readfile($file_path);文件夹将被下载。但我无法解开它。指定的错误是“解压缩失败”。我可以用相同的代码下载一个文件,但不能在文件夹中下载一个文件。请帮忙..。以下是压缩文件的代码:
$zip = new ZipArchive;
if ($zip->open($file_path,ZIPARCHIVE::CREATE) === TRUE) {
if($zip->addEmptyDir('dir1')) {
$zip->addFile($filepath,$destinationPath);
if($zip->addEmptyDir('Files')) {
$zip->addFile($filepath2,$destinationPath2);
}
}
}发布于 2011-03-31 10:31:26
我让密码起作用了..。需要添加$zip->close()代码。
https://stackoverflow.com/questions/5497193
复制相似问题