title: ZipArchive issue "Error 21 - Is a Directory" in PHP
body: <p>I'm generating a set of HTML, CSS, and image files and I'm using ZipArchive to compress them into a zip file. I've confirmed that the generated assets are valid, but when I attempt to zip the set of files, the resulting archive file is not able to be opened.</p>
  
  <p>I'm not getting any errors in the PHP and when I <code>echo $zip-&gt;close()</code> it returns true which I assume to mean that it was able to write to and save the file without issue.  Opening the zip with the mac Archive Utility throws this error:</p>
  
  <blockquote>
    <p>"Unable to expand "filename.zip" into "Downloads".  (Error 21 - Is a
    directory.)</p>
  </blockquote>
  
  <p>What might be wrong here?</p>
  
  <p>Here is the entire PHP script:</p>
  
  <pre><code>&lt;?php
  $ref = $_SERVER["HTTP_REFERER"];
  $html = $_REQUEST['html'];
  $images = $_REQUEST['images'];
  
  $folder = uniqid();
  $prepped = str_replace($ref.'server/php/files/', 'images/', $html);
  
  mkdir("./runways/$folder", 0777);
  mkdir("./runways/$folder/images", 0777);
  mkdir("./runways/$folder/css", 0777);
  
  
  file_put_contents('./runways/'.$folder.'/index.html',$prepped);
  copy('../../css/runway.css', './runways/'.$folder.'/css/runway.css');
  
  foreach($images as $image) {
      $i = urldecode(str_replace($ref.'server/php/files/', '', $image));
      $idata = file_get_contents('./files/'.$i);
      file_put_contents('./runways/'.$folder.'/images/'.$i, $idata);
  
  }
  
  //echo $ref.'server/php/runways/'.$folder.'/';
  
  $sourcefolder = './runways/'.$folder.'/';
  $zipfilename = $folder.'.zip';
  
  $dirlist = new RecursiveDirectoryIterator($sourcefolder);
  $filelist = new RecursiveIteratorIterator($dirlist);
  
  ini_set('max_execution_time', 5000);
  $zip = new ZipArchive();
  
  if ($zip-&gt;open('./zips/'.$zipfilename, ZIPARCHIVE::CREATE) !== TRUE) {
      die ("Could not open archive");
  }
  
  foreach ($filelist as $key=&gt;$value) {
      $zip-&gt;addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
  }
  $zip-&gt;close();
  
  echo $ref.'server/php/zips/'.$zipfilename;
  
  ?&gt;
  </code></pre>