Example #1
0
 /**
  * Builds a path inside the zip. This method will be executed by addFile/addDirectory to
  * build a complete structure inside the zip if a file like /a/b/c/d.txt would be added.
  *
  * @param string $path Path inside the zip file to build.
  * @param bool $is_dir Optional is it a directory or an file defaults to false.
  */
 function buildPath($path, $is_dir = false)
 {
     $pos = strrpos($path, '/');
     if ($pos === false) {
         return;
     }
     $path = substr($path, 0, $pos);
     // Check for dir
     $entry =& $this->getEntryByPath($path);
     if ($entry) {
         return;
     }
     // Dir not found create all parents
     $items = explode('/', $path);
     $path = "";
     if ($is_dir) {
         array_pop($items);
     }
     foreach ($items as $item) {
         $path .= $item . '/';
         // Look for entry
         $entry =& $this->getEntryByPath($path);
         if (!$entry) {
             $entry = new Moxiecode_ZipEntry($this);
             $entry->setPath($path);
             $this->addEntry($entry);
         }
     }
 }
Example #2
0
 /**
  * Opens the zip file for read or write access.
  */
 function open()
 {
     if (!$this->_fp) {
         // Load zip
         if (!file_exists($this->_path)) {
             return;
         }
         $this->_fp = @fopen($this->_path, "rb");
         if ($this->_fp) {
             // Parse local file headers
             while ($header = $this->_readLocalFileHeader()) {
                 /*echo "Local file header:\n";
                 		var_dump($header);*/
                 $entry = new Moxiecode_ZipEntry($this, $header);
                 $this->_entries[] = $entry;
                 $this->_entryLookup[$entry->getPath()] = $entry;
             }
             // Parse central dir headers
             while ($header = $this->_readCentralDirHeader()) {
                 /*echo "Central dir header:\n";
                 		var_dump($header);*/
                 // Append to existing headers
                 for ($i = 0; $i < count($this->_entries); $i++) {
                     $entry = $this->_entries[$i];
                     if ($entry->getPath() == $header['filename']) {
                         $entry->_addHeader($header);
                     }
                 }
             }
             // Parse central dir end header
             if ($header = $this->_readCentralDirEnd()) {
                 /*echo "Central dir end:\n";
                 		var_dump($header);*/
                 $this->_setHeader($header);
             }
         }
     }
 }