title: ZipArchive file is invalid
body: <p>I need a simple function that writes an array of files to one zip file. I found some code from an online tutorial and modified it slightly, but I can't seem to get it to work. It creates the zip file, but when I try and extract it I get an error:</p>
  
  <pre><code>Windows cannot complete the extraction.
  The Compressed (zipped) Folder '...' is invalid.
  </code></pre>
  
  <p>Here's the code I'm working with:</p>
  
  <pre><code>public function create_zip($files = array(),$destination = '',$overwrite = false) {
        //if the zip file already exists and overwrite is false, return false
        if(file_exists($destination) &amp;&amp; !$overwrite) { return 'file exists'; }
  
        $valid_files = array();
        if(is_array($files)) {
          //cycle through each file
          foreach($files as $file) {
            //make sure the file exists
            if(file_exists($file)) {
              $valid_files[] = $file;
            }
          }
        }
        Zend_Debug::dump($valid_files);
  
        if(count($valid_files)) {
          //create the archive
          $zip = new ZipArchive();
          if($zip-&gt;open($destination, ZIPARCHIVE::CREATE) !== true) {
            return 'could not open zip: '.$destination;
          }
          //add the files
          foreach($valid_files as $file) {
            $zip-&gt;addFile($file);
          }
          //debug
          Zend_Debug::dump($zip-&gt;numFiles);
          Zend_Debug::dump($zip-&gt;status);
  
          $zip-&gt;close();
  
          //check to make sure the file exists
          return file_exists($destination);
        } else  {
          return 'no valid failes'. count($valid_files);
        }
  }
  </code></pre>
  
  <p>The debug statements are printing out the following:</p>
  
  <pre><code> For $valid_files - array of one file name (full path to file)
   For $zip-&gt;numFiles - 1
   For $zip-&gt;status - 0
   The function returns true.
  </code></pre>
  
  <p>Any ideas on what I'm doing wrong?</p>