本文整理汇总了PHP中Archive_Tar::extract方法的典型用法代码示例。如果您正苦于以下问题:PHP Archive_Tar::extract方法的具体用法?PHP Archive_Tar::extract怎么用?PHP Archive_Tar::extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Archive_Tar
的用法示例。
在下文中一共展示了Archive_Tar::extract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: inflate
public static function inflate($file, $outputPath)
{
// Sanity
if (!file_exists($file) || !is_file($file) || strtolower(pathinfo($file, PATHINFO_EXTENSION)) != 'tar') {
throw new Engine_Package_Exception('File does not exist or is not a tar file');
}
if (!file_exists($outputPath) || !is_dir($outputPath) || !is_writeable($outputPath)) {
throw new Engine_Package_Exception('Output path does not exist, is not a directory, or is not writeable');
}
self::_loadArchiveClass();
// Make other paths
$outputSubPath = substr(basename($file), 0, strrpos(basename($file), '.'));
$outputFullPath = rtrim($outputPath, '/\\') . DIRECTORY_SEPARATOR . $outputSubPath;
// If output path already exists, remove
if (file_exists($outputFullPath)) {
self::_rmdirRecursive($outputFullPath, true);
}
// Try to make full output path
if (!is_dir($outputFullPath)) {
if (!mkdir($outputFullPath, 0777, true)) {
throw new Engine_Package_Exception('Unable to create output folder');
}
}
// Extract
$archive = new Archive_Tar($file);
$rval = $archive->extract($outputFullPath);
// Throw error if failed
if ($archive->isError($rval)) {
throw new Engine_Package_Exception('Error in archive: ' . $rval->getMessage());
}
return $outputFullPath;
}
示例2: shakeDown
public function shakeDown()
{
$this->logTo = "echo";
$s3 = Mage::helper('cloudbackup')->getS3Client();
// Create the backup and send it to Amazon - don't clean up, otherwise they WILL be different...
list($bucket_name, $key_name) = $this->createBackup(true, false);
// Download it again - save it in /tmp
$s3->getObject($bucket_name, $key_name, "/tmp" . DS . $key_name);
// Extract it in /tmp
$tar = new Archive_Tar("/tmp" . DS . $key_name);
$tar->extract("/tmp/test") or die("Could not extract files!");
// Diff it to check all the files are there - ignore errors about symlinks etc
// TODO: why do we need to remove var/*
// because cache and log entries can change during the running of this test...
$output = exec("diff -rq . /tmp/test 2> /dev/null | grep -v var/");
$this->log($output);
// We expect only the uploaded backup to be different - because we do cleanup=false
if ($output == "Only in .: " . $key_name) {
echo "test passed\n";
//clean up tmp we're all good
exec("rm -f /tmp" . DS . $key_name);
exec("rm -rf /tmp/test");
} else {
echo "test failed\n";
// We don't clean up after a failure - so we can investigate...
}
}
示例3: install
function install($file)
{
G::LoadThirdParty("pear/Archive", "Tar");
$result = array();
$status = 1;
try {
//Extract
$tar = new Archive_Tar($file);
$swTar = $tar->extract(PATH_OUTTRUNK);
//true on success, false on error. //directory for extract
//$swTar = $tar->extract(PATH_PLUGINS);
if (!$swTar) {
throw new Exception("Could not extract file.");
}
//Upgrade
$option = array("http" => array("method" => "POST"));
// Proxy settings
$sysConf = System::getSystemConfiguration();
if (isset($sysConf['proxy_host'])) {
if ($sysConf['proxy_host'] != '') {
if (!is_array($option['http'])) {
$option['http'] = array();
}
$option['http']['request_fulluri'] = true;
$option['http']['proxy'] = 'tcp://' . $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '');
if ($sysConf['proxy_user'] != '') {
if (!isset($option['http']['header'])) {
$option['http']['header'] = '';
}
$option['http']['header'] .= 'Proxy-Authorization: Basic ' . base64_encode($sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : ''));
}
}
}
$context = stream_context_create($option);
///////
$fileData = @fopen(EnterpriseUtils::getUrlServerName() . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/enterprise/services/processMakerUpgrade", "rb", false, $context);
if ($fileData === false) {
throw new Exception("Could not open services url.");
}
$resultAux = G::json_decode(stream_get_contents($fileData));
if ($resultAux->status == "OK") {
$result["status"] = $resultAux->status;
//OK
$result["message"] = $resultAux->message;
} else {
throw new Exception($resultAux->message);
}
} catch (Exception $e) {
$result["message"] = $e->getMessage();
$status = 0;
}
if ($status == 0) {
$result["status"] = "ERROR";
}
return $result;
}
示例4: expand
public static function expand($path)
{
$path = realpath($path);
$dir = dirname($path);
#print ">> $path\n";
$arch = new Archive_Tar($path, true);
$arch->setErrorHandling(PEAR_ERROR_PRINT);
if (false === $arch->extract($dir)) {
throw new Pfw_Exception_Script(Pfw_Exception_Script::E_ARCHIVE_UNKNOWN);
}
}
示例5: array
function archive_extract($path, $archive_dir, $config = array())
{
$result = FALSE;
if (class_exists('Archive_Tar')) {
if (file_safe(path_concat($archive_dir, 'file.txt'), $config)) {
$tar = new Archive_Tar($path);
$tar->extract($archive_dir);
$result = file_exists($archive_dir);
}
}
return $result;
}
示例6: extract_archive
function extract_archive($path, $archive_dir)
{
$result = FALSE;
if (class_exists('Archive_Tar')) {
if (safe_path($archive_dir)) {
$tar = new Archive_Tar($path);
$tar->extract(dirname($archive_dir));
$result = file_exists($archive_dir);
}
}
return $result;
}
示例7: installFromFile
public function installFromFile($file)
{
require_once "/var/www/localhost/htdocs/papyrine/libraries/PEAR.php";
require_once "/var/www/localhost/htdocs/papyrine/libraries/Archive_Tar.php";
$tar = new Archive_Tar($file, 'bz2');
$about = $tar->extractInString("about.xml");
$xml = simplexml_load_string($about);
$dir = "/var/www/localhost/htdocs/papyrine/data/plugins/tmp/" . $xml->id . "/";
if (!is_dir($dir)) {
$tar->extract($dir);
}
$this->installFromDirectory($dir);
}
示例8: extract
/**
* Method to extract an archived and/or compressed file
*
* @param string $to
* @return void
*/
public function extract($to = null)
{
if ($this->compression == 'bz') {
$this->path = Compress\Bzip2::decompress($this->path);
$this->archive = new \Archive_Tar($this->path);
} else {
if ($this->compression == 'gz') {
$this->path = Compress\Gzip::decompress($this->path);
$this->archive = new \Archive_Tar($this->path);
}
}
$this->archive->extract(null !== $to ? $to : './');
}
示例9: _untarIntoTemp
protected function _untarIntoTemp($path)
{
$original_dir = getcwd();
//create a temp file, turn it into a directory
$dir = tempnam('/tmp', 'mt2c');
unlink($dir);
mkdir($dir);
chdir($dir);
$tar = new Archive_Tar($path);
$tar->extract('.');
chdir($original_dir);
return $dir;
}
示例10: install
static function install($source, $filename)
{
$target = SIMPLE_EXT . substr($filename, 0, -3);
setup::out("{t}Download{/t}: " . $source . " ...");
if ($fz = gzopen($source, "r") and $fp = fopen($target, "w")) {
$i = 0;
while (!gzeof($fz)) {
$i++;
setup::out(".", false);
if ($i % 160 == 0) {
setup::out();
}
fwrite($fp, gzread($fz, 16384));
}
gzclose($fz);
fclose($fp);
} else {
sys_die("{t}Error{/t}: gzopen [2] " . $source);
}
setup::out();
if (!file_exists($target) or filesize($target) == 0 or filesize($target) % 10240 != 0) {
sys_die("{t}Error{/t}: file-check [3] Filesize: " . filesize($target) . " " . $target);
}
setup::out(sprintf("{t}Processing %s ...{/t}", basename($target)));
$tar_object = new Archive_Tar($target);
$tar_object->setErrorHandling(PEAR_ERROR_PRINT);
$tar_object->extract(SIMPLE_EXT);
$file_list = $tar_object->ListContent();
if (!is_array($file_list) or !isset($file_list[0]["filename"]) or !is_dir(SIMPLE_EXT . $file_list[0]["filename"])) {
sys_die("{t}Error{/t}: tar [4] " . $target);
}
self::update_modules_list();
$ext_folder = db_select_value("simple_sys_tree", "id", "anchor=@anchor@", array("anchor" => "extensions"));
foreach ($file_list as $file) {
sys_chmod(SIMPLE_EXT . $file["filename"]);
setup::out(sprintf("{t}Processing %s ...{/t}", SIMPLE_EXT . $file["filename"]));
if (basename($file["filename"]) == "install.php") {
setup::out("");
require SIMPLE_EXT . $file["filename"];
setup::out("");
}
if (basename($file["filename"]) == "readme.txt") {
$data = file_get_contents(SIMPLE_EXT . $file["filename"]);
setup::out(nl2br("\n" . q($data) . "\n"));
}
if (!empty($ext_folder) and basename($file["filename"]) == "folders.xml") {
setup::out(sprintf("{t}Processing %s ...{/t}", "folder structure"));
folders::create_default_folders(SIMPLE_EXT . $file["filename"], $ext_folder, false);
}
}
}
示例11: extract
static function extract($target, $folder)
{
setup::out(sprintf("{t}Processing %s ...{/t}", basename($target)));
$tar_object = new Archive_Tar($target);
$tar_object->setErrorHandling(PEAR_ERROR_PRINT);
$tar_object->extract($folder);
$file_list = $tar_object->ListContent();
if (!is_array($file_list) or !isset($file_list[0]["filename"]) or !is_dir($folder . $file_list[0]["filename"])) {
sys_die("{t}Error{/t}: tar [3] " . $target);
}
foreach ($file_list as $file) {
sys_chmod($folder . $file["filename"]);
}
@unlink($target);
return $folder . $file_list[0]["filename"];
}
示例12: prepare
/**
* preprocess Index action.
*
* @access public
* @return string Forward name (null if no errors.)
*/
function prepare()
{
if ($this->af->validate() == 0) {
list($package, $version) = explode('@', $this->af->get('target_package'));
$data_file = $this->backend->ctl->package2dataFile($package, $version);
require_once 'Archive/Tar.php';
$tar = new Archive_Tar($data_file, 'gz');
$status = $tar->extract(dirname($data_file));
/* chdir(BASE.'/tmp');
exec('which tar', $which, $status);
$command = sprintf('%s xzf %s', $which[0], $data_file);
exec($command, $result, $status); */
if ($status == 1) {
return null;
}
$this->ae->add('extract_error', _('file extract error') . sprintf('[STATUS: %s]', $status));
}
return 'json_error_reload';
}
示例13: extract
/**
* @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 'tar':
case 'tgz':
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':
case 'tbz':
case 'tbz2':
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':
require_once dirname(__FILE__) . '/Tar.php';
$archive = new Archive_Tar($archivename);
$result = $archive->extract($extractdir);
break;
/*
default :
$adapter = & extArchive::getAdapter( $ext ) ;
if( $adapter ) {
$result = $adapter->extract( $archivename, $extractdir ) ;
} else {
return PEAR::raiseError('Unknown Archive Type: '.$ext );
}
break ;
*/
}
return $result;
}
示例14: nc_tgz_extract
function nc_tgz_extract($archive_name, $dst_path)
{
global $DOCUMENT_ROOT;
@set_time_limit(0);
if (SYSTEM_TAR) {
exec("cd {$DOCUMENT_ROOT}; tar -zxf {$archive_name} -C {$dst_path} 2>&1", $output, $err_code);
if ($err_code && !strpos($output[0], "time")) {
// ignore "can't utime, permission denied"
trigger_error("{$output['0']}", E_USER_WARNING);
return false;
}
return true;
} else {
$current_dir = realpath('.');
chdir($DOCUMENT_ROOT);
$tar_object = new Archive_Tar($archive_name, "gz");
$tar_object->setErrorHandling(PEAR_ERROR_PRINT);
$result = $tar_object->extract($dst_path);
chdir($current_dir);
return $result;
}
}
示例15: extractTar
protected function extractTar($extractLocation)
{
if (!class_exists('Archive_Tar')) {
return Result::errorMissingPackage($this, 'Archive_Tar', 'pear/archive_tar');
}
$tar_object = new \Archive_Tar($this->filename);
if (!$tar_object->extract($extractLocation)) {
return Result::error($this, "Could not extract tar archive {$this->filename}");
}
return Result::success($this);
}