How to download a zipped file in php? [duplicate]
Possible Duplicate:
How to zip a whole folder using PHP
Hi, I am creating a zip folder using zipArchive in php.The zipped file contains a folder(with a file in it) and a file. I am using the following code to download the zipped file:
$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);
The folder gets downloaded. But I am unable to unzip it. The error specified is "Decompression failed". I can download a single file with the same code but not a file within a folder. Please help.. Here is the code to zip the files:
$zip = new ZipArchive;
if ($zip->open($file_path,ZIPARCHIVE::CREATE) === TRUE) {
if($z开发者_StackOverflowip->addEmptyDir('dir1')) {
$zip->addFile($filepath,$destinationPath);
if($zip->addEmptyDir('Files')) {
$zip->addFile($filepath2,$destinationPath2);
}
}
}
I got the code working... Need to add a $zip->close() code.
精彩评论