title: Creating and downloading ZipArchive fails on PHP 5.1, works on PHP 5.4
body: <p>The following class is failing with ZipArchive error 23 - "Entry has been deleted" when attempting to add a new empty dir that is nested in another added empty dir. Ex:</p>
  
  <pre><code>dir1:
      file1
      file2
      ...
  </code></pre>
  
  <p>works just fine, but something like:</p>
  
  <pre><code>dir1:
      dir2:
          file1
          ...
      file1
      file1
      ...
  </code></pre>
  
  <p>will fail when attempting to add <code>dir1/dir2</code>.</p>
  
  <p><strong>Downloader Class</strong></p>
  
  <pre><code>class Downloader {
  
      var $path, $tmp, $zip, $txt, $selected;
  
      function __construct($selected) {
          global $webroot;
  
          $this-&gt;path = $webroot.'downloads/';
          $this-&gt;tmp = tempnam('../tmp', 'dln');
          $this-&gt;zip = new ZipArchive();
          $this-&gt;zip-&gt;open($this-&gt;tmp, ZipArchive::OVERWRITE);
          $this-&gt;txt = '';
          $this-&gt;selected = $selected;
      }
  
      public function incl_file($name) {
          $this-&gt;zip-&gt;addFile($this-&gt;path.$name, $name);
      }
  
      public function incl_dir($name) {
          $this-&gt;zip-&gt;addEmptyDir($name);
          $files = new DirectoryIterator($this-&gt;path.$name.'/');
          foreach ($files as $file) {
              if (!$file-&gt;isDot()) {
                  if ($file-&gt;isDir()) {
                      $this-&gt;incl_dir($name.'/'.$file-&gt;getFilename());
                  } else {
                      $this-&gt;incl_file($name.'/'.$file-&gt;getFilename());
                  }
              }
          }
      }
  
      public function download($downloadObj) {
          $selected = preg_split('/,/', $this-&gt;selected);
          foreach ($selected as $name) {
              $this-&gt;txt .= file_get_contents($this-&gt;path.$name.'.snip');
  
              foreach ($downloadObj-&gt;files as $file) {
                  if ($name == $file-&gt;name) {
                      // check to see if there are files to include
                      if (strlen($file-&gt;incl_files) &gt; 0) {
                          // if so, get include directories
                          $incl_dirs = preg_split('/,/', $file-&gt;incl_dir);
                          // iterate include directories
                          foreach ($incl_dirs as $dir) {
                              // get include file groups
                              $incl_file_groups = preg_split('/,/', $file-&gt;incl_files);
                              // iterate include file groups
                              foreach ($incl_file_groups as $group) {
                                  // get individual include files
                                  $incl_files = preg_split('/\|/', $group);
                                  // iterate individual include files
                                  foreach ($incl_files as $f) {
                                      // check to see if all files in include dir should be inserted
                                      if ($f == '*') {
                                          $this-&gt;incl_dir($dir);
                                      } else {
                                          $path = '';
                                          if ($dir == "/") {
                                              $path = $f;
                                          } else {
                                              $path .= $dir.'/'.$f;
                                          }
                                          $this-&gt;incl_file($path);
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
          }
          $this-&gt;txt = file_get_contents($this-&gt;path.'header.inc').$this-&gt;txt.file_get_contents($this-&gt;path.'footer.inc');
          $this-&gt;zip-&gt;addFromString('DownloadTemplate.xml', $this-&gt;txt);
          $this-&gt;zip-&gt;close();
          $filename = 'MyDownload.zip';
          header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
          header('Last-Modified: ' . gmdate('D,d M YH:i:s') . ' GMT');
          header('Cache-Control: no-cache, must-revalidate');
          header('Pragma: no-cache');
          header('Content-type: application/zip');
          header('Content-Disposition: attachment; filename='.$filename);
          header('Content-Transfer-Encoding: binary');
          readfile($this-&gt;tmp);
          unlink($this-&gt;tmp);
      }
  }
  </code></pre>