1

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($zip->addEmptyDir('dir1')) {
       $zip->addFile($filepath,$destinationPath);
       if($zip->addEmptyDir('Files')) {
           $zip->addFile($filepath2,$destinationPath2);
       } 
   }
}
Community
  • 1
  • 1
Sangam254
  • 3,415
  • 11
  • 33
  • 43

1 Answers1

0

I got the code working... Need to add a $zip->close() code.

Sangam254
  • 3,415
  • 11
  • 33
  • 43