Exemplo n.º 1
0
 /**
  * Extract a ZIP compressed file to a given path
  *
  * @access	public
  * @param	string	$archive		Path to ZIP archive to extract
  * @param	string	$destination	Path to extract archive into
  * @param	array	$options		Extraction options [unused]
  * @return	boolean	True if successful
  * @since	1.5
  */
 function extract($archive, $destination, $options = array())
 {
     // Initialize variables
     $this->_data = null;
     $this->_metadata = null;
     if (!($this->_data = file_get_contents($archive))) {
         return PEAR::raiseError('Unable to read archive');
     }
     if (!$this->_getTarInfo($this->_data)) {
         return PEAR::raiseError('Unable to decompress data');
     }
     for ($i = 0, $n = count($this->_metadata); $i < $n; $i++) {
         $type = strtolower($this->_metadata[$i]['type']);
         if ($type == 'file' || $type == 'unix file') {
             $buffer = $this->_metadata[$i]['data'];
             $path = extPath::clean($destination . DS . $this->_metadata[$i]['name']);
             // Make sure the destination folder exists
             if (!extMkdirR(dirname($path))) {
                 return PEAR::raiseError('Unable to create destination');
             }
             if (file_put_contents($path, $buffer) === false) {
                 return PEAR::raiseError('Unable to write entry');
             }
         }
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * Extract a ZIP compressed file to a given path using a php based algorithm that only requires zlib support
  *
  * @access	private
  * @param	string	$archive		Path to ZIP archive to extract
  * @param	string	$destination	Path to extract archive into
  * @param	array	$options		Extraction options [unused]
  * @return	boolean	True if successful
  * @since	1.5
  */
 function _extract($archive, $destination, $options)
 {
     // Initialize variables
     $this->_data = null;
     $this->_metadata = null;
     if (!extension_loaded('zlib')) {
         return PEAR::raiseError('Zlib Not Supported');
     }
     if (!($this->_data = file_get_contents($archive))) {
         return PEAR::raiseError('Unable to read archive');
     }
     if (!$this->_getZipInfo($this->_data)) {
         return false;
     }
     for ($i = 0, $n = count($this->_metadata); $i < $n; $i++) {
         if (substr($this->_metadata[$i]['name'], -1, 1) != '/' && substr($this->_metadata[$i]['name'], -1, 1) != '\\') {
             $buffer = $this->_getFileData($i);
             $path = extPath::clean($destination . DS . $this->_metadata[$i]['name']);
             // Make sure the destination folder exists
             if (!extMkdirR(dirname($path))) {
                 return PEAR::raiseError('Unable to create destination');
             }
             if (file_put_contents($path, $buffer) === false) {
                 return PEAR::raiseError('Unable to write entry');
             }
         }
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * Wrapper for the standard file_exists function
  *
  * @param string $file File path
  * @return boolean True if path is a file
  * @since 1.5
  */
 function exists($file)
 {
     return is_file(extPath::clean($file));
 }
Exemplo n.º 4
0
 /**
  * Wrapper for the standard file_exists function
  *
  * @param string $path Folder name relative to installation dir
  * @return boolean True if path is a folder
  * @since 1.5
  */
 function exists($path)
 {
     return is_dir(extPath::clean($path));
 }
Exemplo n.º 5
0
 /**
  * @param	string	The name of the archive file
  * @param	string	Directory to unpack into
  * @return	boolean	True for success
  */
 function extract($archivename, $extractdir)
 {
     require_once dirname(__FILE__) . '/file.php';
     require_once dirname(__FILE__) . '/folder.php';
     $untar = false;
     $result = false;
     $ext = extFile::getExt(strtolower($archivename));
     // check if a tar is embedded...gzip/bzip2 can just be plain files!
     if (extFile::getExt(extFile::stripExt(strtolower($archivename))) == 'tar') {
         $untar = true;
     }
     switch ($ext) {
         case 'zip':
             $adapter =& extArchive::getAdapter('zip');
             if ($adapter) {
                 $result = $adapter->extract($archivename, $extractdir);
             }
             break;
         case 'tar':
             $adapter =& extArchive::getAdapter('tar');
             if ($adapter) {
                 $result = $adapter->extract($archivename, $extractdir);
             }
             break;
         case 'tgz':
             $untar = true;
             // This format is a tarball gzip'd
         // This format is a tarball gzip'd
         case 'gz':
             // This may just be an individual file (e.g. sql script)
         // This may just be an individual file (e.g. sql script)
         case 'gzip':
             $adapter =& extArchive::getAdapter('gzip');
             if ($adapter) {
                 $tmpfname = (defined('_EXT_FTPTMP_PATH') ? _EXT_FTPTMP_PATH . '/' : $extractdir) . uniqid('gzip');
                 $gzresult = $adapter->extract($archivename, $tmpfname);
                 if (!$gzresult) {
                     unlink($tmpfname);
                     return false;
                 }
                 if ($untar) {
                     // Try to untar the file
                     $tadapter =& extArchive::getAdapter('tar');
                     if ($tadapter) {
                         $result = $tadapter->extract($tmpfname, $extractdir);
                     }
                 } else {
                     $path = extPath::clean($extractdir);
                     mkdir($path);
                     $result = copy($tmpfname, $path . DS . extFile::stripExt(extFile::getName(strtolower($archivename))));
                 }
                 @unlink($tmpfname);
             }
             break;
         case 'tbz2':
             $untar = true;
             // This format is a tarball bzip2'd
         // This format is a tarball bzip2'd
         case 'bz2':
             // This may just be an individual file (e.g. sql script)
         // This may just be an individual file (e.g. sql script)
         case 'bzip2':
             $adapter =& extArchive::getAdapter('bzip2');
             if ($adapter) {
                 $tmpfname = _EXT_FTPTMP_PATH . '/' . uniqid('bzip2');
                 $bzresult = $adapter->extract($archivename, $tmpfname);
                 if (!$bzresult) {
                     @unlink($tmpfname);
                     return false;
                 }
                 if ($untar) {
                     // Try to untar the file
                     $tadapter =& extArchive::getAdapter('tar');
                     if ($tadapter) {
                         $result = $tadapter->extract($tmpfname, $extractdir);
                     }
                 } else {
                     $path = extPath::clean($extractdir);
                     mkdir($path);
                     $result = copy($tmpfname, $path . DS . extFile::stripExt(extFile::getName(strtolower($archivename))));
                 }
                 @unlink($tmpfname);
             }
             break;
         default:
             return PEAR::raiseError('Unknown Archive Type: ' . $ext);
             break;
     }
     return $result;
 }