title: Create a ZIP file script not creating ZIPs (no errors)
body: <p>I'm not a native PHP developer but I make do with what I can find and hack together out there, so please excuse me if this doesn't make too much sense:</p>
  
  <p>I have a simple (so it seems) script that takes two arguments in the URL. One is a simple string (title of the ZIP to be created) and the other is a serialized array of audio tracks that point to the files on the server that need zipping. These then pass just fine and are unserialized etc. Here's the script:</p>
  
  <pre><code>&lt;?php
  
  $audioTitleVar = unserialize(rawurldecode($_GET['audioTitle']));
  $audioArrayVar = unserialize(rawurldecode($_GET['audioArray']));
  
  function create_zip( $files = array(), $destination = '', $overwrite = true ) {
  
      if(file_exists($destination) &amp;&amp; !$overwrite) { return false; }
  
      $valid_files = array();
  
      if(is_array($files)) {
          foreach($files as $file) {
              if( file_exists($_SERVER['DOCUMENT_ROOT'] . str_replace("http://mydomain.com","", $file)) ) {
                  $valid_files[] = $_SERVER['DOCUMENT_ROOT'] . str_replace("http://mydomain.com","", $file);
              }
          }
      }
  
      if(count($valid_files)) {
  
          $zip = new ZipArchive();
  
          if($zip-&gt;open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
              return false;
          }
  
          foreach( $valid_files as $file ) {
              $just_name = preg_replace("/(.*)\/?([^\/]+)/","$2",$file);
              $zip-&gt;addFile($file,$just_name);
              //$zip-&gt;addFile($file,$file); 
          }
  
          //echo '&lt;p&gt;The zip archive contains ' . $zip-&gt;numFiles . ' files with a status of ' . $zip-&gt;status . '&lt;/p&gt;';        
          $zip-&gt;close();
          return file_exists($destination);
  
      } else {
          return false;
      }
  
  }
  
  $fileName = $_SERVER['DOCUMENT_ROOT'] . '/wp-content/themes/jones/zip/' . $audioTitleVar . '.zip';
  create_zip( $audioArrayVar, $fileName, true );
  //echo '&lt;p&gt;File Path: ' . $fileName . '&lt;/p&gt;';
  var_dump(file_exists($fileName));
  
  ?&gt;
  </code></pre>
  
  <p>I guess my real issue here, is that, although the script DOES NOT error...no ZIP is created. I have, over time placed outputs in the function at certain parts to see if it was even getting there, and it is - so I'm stumped on this.</p>
  
  <p>What I really need is for one of you guys to scan the script over to see if there's anything glaringly obvious that just won't work!</p>
  
  <p>Could it be a permissions thing? Should PHP be running in CGI mode or Apache? Or does this not make a difference?</p>
  
  <p>The bones of this script were taken from: <a href="http://davidwalsh.name/create-zip-php" rel="nofollow">http://davidwalsh.name/create-zip-php</a> but it's never worked even with that version alone.</p>
  
  <p>PS - I'd just like to add, that if I uncomment the line that tells me how many files are in the ZIP etc, it seems to return the correct info...but the final check on whether the file exists returns false.</p>