title: Debugging zip archive and download
body: <p>I'd  like a bit of help debugging this code. I'm trying to zip some files, which I provide as paths to Ziparchive. I think the zip file is empty, possibly. When I test this on a staging site I get a 'decompression failed' error. When I test this locally I get the following error in php logs</p>
  
  <blockquote>
    <p>PHP Warning:  readfile(images.zip): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/8018_Whites/wordpress/downloadzip.php on line 29.</p>
  </blockquote>
  
  <p>Here is the code: </p>
  
  <pre><code>&lt;?php
  
  //get image urls string
  //$cat_string = "url1,url2,url3..."
  if (isset($_GET['category-images'])) {
      $cat_string=$_GET['category-images'];
  }
  //change string to array
  $cat_array=explode(",", $cat_string);
  $files=$cat_array;
  
  $zipname = 'images.zip';
  $zip = new ZipArchive;
  $zip-&gt;open($zipname, ZipArchive::CREATE);
  foreach ($files as $file) {
    if(!strstr($file,'.php')) $zip-&gt;addFile($file);
  }
  $zip-&gt;close();
  
  if ($zipname) {
  header('Content-Type: application/zip');
  header('Content-disposition: attachment; filename='.$zipname);
  header('Content-Length: ' . filesize($zipname));
  readfile($zipname);
  exit();
  }
  ?&gt;
  </code></pre>
  
  <p>Do I need to add ob_start/ob_flush to this code, and should I put the ob_flush after readfile?</p>