Example #1
0
 /**
  * Adds a directory inside the zip file. This can be an empty directory or a local directory that
  * is to be added to the zip.
  *
  * @param string $zip_path Path to store the directory as inside the zip. For example /mydir/dir.
  * @param string $path Optional local file path for example c:/mydir.
  * @param string $comment Optional comment to add for directory inside the zip file.
  * @param bool $recursive Optional state to do a recursive add or not this is true by default.
  */
 function addDirectory($zip_path, $path = "", $comment = "", $recursive = true)
 {
     $zip_path = preg_replace('/^\\//', '', $zip_path);
     $zip_path = $this->_addTrailingSlash($zip_path);
     $this->deleteDir($zip_path);
     if ($path) {
         $path = realpath($path);
         $files = $this->_listTree($path, $recursive);
         foreach ($files as $file) {
             $entry = new Moxiecode_ZipEntry($this);
             $entry->setPath($zip_path . substr($file, strlen($path) + 1));
             $entry->setLocalPath($file);
             $entry->setComment($comment);
             $entry->setType(is_dir($file));
             $this->addEntry($entry);
             $this->buildPath($entry->getPath(), is_dir($file));
         }
         $this->buildPath($zip_path . substr($file, strlen($path) + 1), is_dir($file));
     } else {
         $entry = new Moxiecode_ZipEntry($this);
         $entry->setPath($zip_path);
         $entry->setComment($comment);
         $entry->setType(1);
         $this->addEntry($entry);
         $this->buildPath($entry->getPath());
     }
 }