title: How to download a zipped file in php?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php">How to zip a whole folder using PHP</a>  </p>
  </blockquote>
  
  
  
  <p>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:</p>
  
  <pre><code>$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);
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>$zip = new ZipArchive;
  if ($zip-&gt;open($file_path,ZIPARCHIVE::CREATE) === TRUE) {
  
     if($zip-&gt;addEmptyDir('dir1')) {
         $zip-&gt;addFile($filepath,$destinationPath);
         if($zip-&gt;addEmptyDir('Files')) {
             $zip-&gt;addFile($filepath2,$destinationPath2);
         } 
     }
  }
  </code></pre>