protected function extractArchive(PhingFile $zipfile) { $extractParams = array('add_path' => $this->todir->getAbsolutePath()); if (!empty($this->removepath)) { $extractParams['remove_path'] = $this->removepath; } $this->log("Extracting zip: " . $zipfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO); try { $zip = new Archive_Zip($zipfile->getAbsolutePath()); $extractResponse = $zip->extract($extractParams); if (is_array($extractResponse)) { foreach ($extractResponse as $extractedPath) { $this->log('Extracted' . $extractedPath['stored_filename'] . ' to ' . $this->todir->__toString(), Project::MSG_VERBOSE); } } else { if ($extractResponse === 0) { throw new BuildException('Failed to extract zipfile: ' . $zip->errorInfo(true)); } } } catch (IOException $ioe) { $msg = "Could not extract ZIP: " . $ioe->getMessage(); throw new BuildException($msg, $ioe, $this->getLocation()); } }
/** * @param string The name of the archive * @param mixed The name of a single file or an array of files * @param string The compression for the archive * @param string Path to add within the archive * @param string Path to remove within the archive * @param boolean Automatically append the extension for the archive * @param boolean Remove for source files */ function create($archive, $files, $compress = 'tar', $addPath = '', $removePath = '', $autoExt = false, $cleanUp = false) { $compress = strtolower($compress); if ($compress == 'tgz' || $compress == 'tbz' || $compress == 'tar') { require_once _EXT_PATH . '/libraries/Tar.php'; if (is_string($files)) { $files = array($files); } if ($autoExt) { $archive .= '.' . $compress; } if ($compress == 'tgz') { $compress = 'gz'; } if ($compress == 'tbz') { $compress = 'bz2'; } $tar = new Archive_Tar($archive, $compress); $tar->setErrorHandling(PEAR_ERROR_PRINT); $result = $tar->addModify($files, $addPath, $removePath); return $result; } if ($compress == 'zip') { /*require_once( _EXT_PATH.'/libraries/lib_zip.php' ); $zip = new ZipFile(); $zip->addFileList($files, $removePath ); return $zip->save($archive); */ require_once _EXT_PATH . '/libraries/Zip.php'; $zip = new Archive_Zip($archive); $result = $zip->add($files, array('add_path' => $addPath, 'remove_path' => $removePath)); /*require_once( _EXT_PATH.'/libraries/pclzip.lib.php' ); $zip = new PclZip($archive); $result = $zip->add($files, PCLZIP_OPT_ADD_PATH, $addPath, PCLZIP_OPT_REMOVE_PATH, $removePath ); */ if ($result == 0) { return new PEAR_Error('Unrecoverable error "' . $zip->errorInfo(true) . '"'); } } }
function execAction($dir, $item) { global $mosConfig_absolute_path; if (!ext_isArchive($item)) { ext_Result::sendResult('archive', false, ext_Lang::err('extract_noarchive')); } else { $archive_name = realpath(get_abs_item($dir, $item)); $file_info = pathinfo($archive_name); if (empty($dir)) { $extract_dir = realpath($GLOBALS['home_dir']); } else { $extract_dir = realpath($GLOBALS['home_dir'] . "/" . $dir); } $ext = $file_info["extension"]; switch ($ext) { case "zip": require_once _EXT_PATH . "/libraries/Zip.php"; $extract_dir = str_replace('\\', '/', $extract_dir); $zip = new Archive_Zip($archive_name); $res = $zip->extract(array('add_path' => $extract_dir)); if ($res == 0) { ext_Result::sendResult('extract', false, ext_Lang::err('extract_failure') . ' (' . $zip->errorInfo(true) . ')'); } else { ext_Result::sendResult('extract', false, ext_Lang::msg('extract_success')); } break; case "gz": // a // a case "bz": // lot // lot case "bz2": // of // of case "bzip2": // fallthroughs, // fallthroughs, case "tbz": // don't // don't case "tar": // wonder require_once _EXT_PATH . "/libraries/Tar.php"; $archive = new Archive_Tar($archive_name); if ($archive->extract($extract_dir)) { ext_Result::sendResult('extract', true, ext_Lang::msg('extract_success')); } else { ext_Result::sendResult('extract', false, ext_Lang::err('extract_failure')); } break; default: ext_Result::sendResult('extract', false, ext_Lang::err('extract_unknowntype')); break; } /* require_once (_EXT_PATH . "/libraries/Archive/archive.php") ; $result = extArchive::extract( $archive_name, $extract_dir ) ; if( PEAR::isError( $result ) ) { ext_Result::sendResult( 'extract', false, ext_Lang::err( 'extract_failure' ) . ': ' . $result->getMessage() ) ; } */ ext_Result::sendResult('extract', true, ext_Lang::msg('extract_success')); } }