title: ZipArchive::close(): Read error: Is a directory
body: <p>I'm trying to figure out this problem but I cannot imagine why it keeps happening. I'm adding files to a ZipArchive and when I try to close it, it get the error that the destination is a directory. But I'm pretty sure it is not.</p>
  
  <p>This is the code of the zip function:</p>
  
  <pre><code>function create_zip($folder, $destination) {
      $valid_files = get_files($folder);
      if(count($valid_files)) {       
          $zip = new ZipArchive();
          if($zip-&gt;open($destination, ZIPARCHIVE::CREATE) !== true) {
              return false;
          }
          //add the files
          foreach($valid_files as $file) {
              $zip-&gt;addFile($file,$file);
          }
          $zip-&gt;close();
          return file_exists($destination);
      }
      else
      {
          return false;
      }
  }
  
  function get_files($folder){
      $valid_files = array();
      $files = scandir($folder);
      foreach($files as $file) {
          if(substr($file, 0, 1) == "." || !is_readable($folder . '/' . $file)) {
              continue;
          }
          if(is_dir($file)){
              array_merge($valid_files, get_files($folder . '/' . $file));
          } else {
              $valid_files[] = $folder . '/' . $file;
          }
      }
      return $valid_files;
  }
  </code></pre>
  
  <p>I'm calling it like this so it should really not be a directory:</p>
  
  <pre><code>$dest = "backups/" . time() . "_backup.zip";
  if(file_exists($dest)){
      if(is_dir($dest)) {
          rmdir($dest);
      } else {
          unlink($dest);  
      }
  }
  create_zip('crawler/out', $dest);
  </code></pre>
  
  <p>Maybe someone here can help me with this. Thank you!</p>
  
  <p>Simon</p>