title: zip and download files using php
body: <p>I am trying to zip and download files from a folder named "upload".
  Zip file is downloading but I couldn't open (extract) it.
  I am getting an error like "The archive is either in unknown format or damaged".</p>
  
  <p>I have found the following code to zip the folder.</p>
  
  <pre><code>&lt;?php
      $files = "upload/".array('Dear GP.docx','ecommerce.doc');
      $zipname = 'filename.zip';
      $zip = new ZipArchive;
      $zip-&gt;open($zipname, ZipArchive::CREATE);
      foreach ($files as $file) {
        $zip-&gt;addFile($file);
      }
      $zip-&gt;close();
      header('Content-Type: application/zip');
      header('Content-disposition: attachment; filename=filename.zip');
      header('Content-Length: ' . filesize($zipfilename));
      readfile($zipname);
  ?&gt;
  </code></pre>