Creating and downloading ZipArchive fails on PHP 5.1, works on PHP 5.4 -


the following class failing ziparchive error 23 - "entry has been deleted" when attempting add new empty dir nested in added empty dir. ex:

dir1:     file1     file2     ... 

works fine, like:

dir1:     dir2:         file1         ...     file1     file1     ... 

will fail when attempting add dir1/dir2.

downloader class

class downloader {      var $path, $tmp, $zip, $txt, $selected;      function __construct($selected) {         global $webroot;          $this->path = $webroot.'downloads/';         $this->tmp = tempnam('../tmp', 'dln');         $this->zip = new ziparchive();         $this->zip->open($this->tmp, ziparchive::overwrite);         $this->txt = '';         $this->selected = $selected;     }      public function incl_file($name) {         $this->zip->addfile($this->path.$name, $name);     }      public function incl_dir($name) {         $this->zip->addemptydir($name);         $files = new directoryiterator($this->path.$name.'/');         foreach ($files $file) {             if (!$file->isdot()) {                 if ($file->isdir()) {                     $this->incl_dir($name.'/'.$file->getfilename());                 } else {                     $this->incl_file($name.'/'.$file->getfilename());                 }             }         }     }      public function download($downloadobj) {         $selected = preg_split('/,/', $this->selected);         foreach ($selected $name) {             $this->txt .= file_get_contents($this->path.$name.'.snip');              foreach ($downloadobj->files $file) {                 if ($name == $file->name) {                     // check see if there files include                     if (strlen($file->incl_files) > 0) {                         // if so, include directories                         $incl_dirs = preg_split('/,/', $file->incl_dir);                         // iterate include directories                         foreach ($incl_dirs $dir) {                             // include file groups                             $incl_file_groups = preg_split('/,/', $file->incl_files);                             // iterate include file groups                             foreach ($incl_file_groups $group) {                                 // individual include files                                 $incl_files = preg_split('/\|/', $group);                                 // iterate individual include files                                 foreach ($incl_files $f) {                                     // check see if files in include dir should inserted                                     if ($f == '*') {                                         $this->incl_dir($dir);                                     } else {                                         $path = '';                                         if ($dir == "/") {                                             $path = $f;                                         } else {                                             $path .= $dir.'/'.$f;                                         }                                         $this->incl_file($path);                                     }                                 }                             }                         }                     }                 }             }         }         $this->txt = file_get_contents($this->path.'header.inc').$this->txt.file_get_contents($this->path.'footer.inc');         $this->zip->addfromstring('downloadtemplate.xml', $this->txt);         $this->zip->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->tmp);         unlink($this->tmp);     } } 

pre-php 5.2 zip installed through different means. when updated 5.4, compiled, or istalled zip extension php , didn't have on 5.1