function dl_remote($remote, $file, $local) { $meat = $this->get_remote($remote . "/Dist/" . $file . ".tgz"); if ($meat) { $localfile = $local . "/Cache/" . $file . ".tgz"; if (is_file($localfile)) { unlink($localfile); } $fp = fopen($localfile, "wb"); fwrite($fp, $meat); fclose($fp); require "lib/tar.class.php"; $tar = new tar(); if ($tar->openTAR($localfile)) { foreach ($tar->files as $f) { $this->prepare_dir(dirname($local . '/' . $f['name'])); $fp = fopen($local . '/' . $f['name'], "wb"); fwrite($fp, $f['file'], $f['size']); fclose($fp); } } else { $this->feedback[] = array('num' => 1, 'mes' => sprintf(tra('File %s is not a valid archive'), $localfile)); return false; } } else { $this->feedback[] = array('num' => 1, 'mes' => sprintf(tra('%s is an empty archive file'), $file)); return false; } }
function main() { $tar = new tar(); $tar->addFile('./test.pdf'); $tar->toTar('./test_create.tar', false); $tar1 = new tar(); $opened = $tar1->openTAR('./test_create.tar'); if ($opened) { $soubor = $tar1->getFile('./test.pdf'); echo $soubor["file"]; } else { echo "FAILED TO OPEN ARCHIVE"; } }
/** * Untar a downloaded tar ball * * @return array Returns file list */ function _unPack() { require_once _XE_PATH_ . 'libs/tar.class.php'; $oTar = new tar(); $oTar->openTAR($this->download_file); $_files = $oTar->files; $file_list = array(); if (is_array($_files)) { foreach ($_files as $key => $info) { FileHandler::writeFile($this->download_path . "/" . $info['name'], $info['file']); $file_list[] = $info['name']; } } return $file_list; }
/** * import layout * @param int $layout_srl * @param string $source_file path of imported file * @return void */ function importLayout($layout_srl, $source_file) { $oLayoutModel = getModel('layout'); $user_layout_path = FileHandler::getRealPath($oLayoutModel->getUserLayoutPath($layout_srl)); $file_list = $oLayoutModel->getUserLayoutFileList($layout_srl); foreach ($file_list as $key => $file) { FileHandler::removeFile($user_layout_path . $file); } require_once _XE_PATH_ . 'libs/tar.class.php'; $image_path = $oLayoutModel->getUserLayoutImagePath($layout_srl); FileHandler::makeDir($image_path); $tar = new tar(); $tar->openTAR($source_file); // If layout.ini file does not exist if (!$tar->getFile('layout.ini')) { return; } $replace_path = getNumberingPath($layout_srl, 3); foreach ($tar->files as $key => $info) { FileHandler::writeFile($user_layout_path . $info['name'], str_replace('__LAYOUT_PATH__', $replace_path, $info['file'])); } // Remove uploaded file FileHandler::removeFile($source_file); }
$REX[version] = "2.7"; // ----- db anlegen $file_temp = "include/install/community0.5_redaxo2.7.sql"; $h = fopen($file_temp, "r"); $conts = fread($h, filesize($file_temp)); $all = explode("\n", $conts); $add = new sql(); // $add->debugsql = 1; foreach ($all as $hier) { $add->setquery(Trim(str_replace("||||||+N+||||||", "\n", $hier), ";")); $add->flush(); } // ----- dateien anlegen $file_temp = $REX[INCLUDE_PATH] . "/install/community0.5_redaxo2.7.tar.gz"; $tar = new tar(); $tar->openTAR($file_temp); if (!$tar->extractTar()) { $err_msg = $I18N->msg("problem_when_extracting") . "<br>"; if (count($tar->message) > 0) { $err_msg .= $I18N->msg("create_dirs_manually") . "<br>"; reset($tar->message); for ($fol = 0; $fol < count($tar->message); $fol++) { $err_msg .= key($tar->message) . "<br>"; next($tar->message); } } } } elseif ($dbanlegen == 3) { // ----- update $fname = "include/install/update2_6-2_7.sql"; $h = fopen($fname, "r");
public function procShopToolUserSkinImport(){ if(!$this->module_srl) exit(); // check upload if(!Context::isUploaded()) exit(); $file = Context::get('file'); if(!is_uploaded_file($file['tmp_name'])) exit(); if(!preg_match('/\.(tar)$/i', $file['name'])) exit(); $oShopModel = $this->model; $skin_path = FileHandler::getRealPath($oShopModel->getShopPath($this->module_srl)); $tar_file = $skin_path . 'shop_skin.tar'; FileHandler::removeDir($skin_path); FileHandler::makeDir($skin_path); if(!move_uploaded_file($file['tmp_name'], $tar_file)) exit(); require_once(_XE_PATH_.'libs/tar.class.php'); $tar = new tar(); $tar->openTAR($tar_file); if(!$tar->getFile('shop.html')) return; $replace_path = getNumberingPath($this->module_srl,3); foreach($tar->files as $key => $info) { FileHandler::writeFile($skin_path . $info['name'],str_replace('__SHOP_SKIN_PATH__',$replace_path,$info['file'])); } FileHandler::removeFile($tar_file); }
/** * Importiert das Tar-Archiv $filename in den Ordner /files * * @param string Pfad + Dateinamen zum Tar-Archiv * * @return array Gibt ein Assoc. Array zurück. * 'state' => boolean (Status ob fehler aufgetreten sind) * 'message' => Evtl. Status/Fehlermeldung */ function rex_a1_import_files($filename) { global $REX, $I18N_IM_EXPORT; $return = array(); $return['state'] = false; if ($filename == '') { $return['message'] = $I18N_IM_EXPORT->msg("no_import_file_chosen") . "<br>"; return $return; } // Ordner /files komplett leeren rex_deleteDir($REX['INCLUDE_PATH'] . "/../../files"); $tar = new tar(); $tar->openTAR($filename); if (!$tar->extractTar()) { $msg = $I18N_IM_EXPORT->msg("problem_when_extracting") . "<br>"; if (count($tar->message) > 0) { $msg .= $I18N_IM_EXPORT->msg("create_dirs_manually") . "<br>"; reset($tar->message); for ($fol = 0; $fol < count($tar->message); $fol++) { $msg .= rex_absPath(str_replace("'", "", key($tar->message))) . "<br>"; next($tar->message); } } } else { $msg = $I18N_IM_EXPORT->msg("file_imported") . "<br>"; } $return['state'] = true; $return['message'] = $msg; return $return; }
} else { $contents =& $gz_contents; } $output .= rcms_parse_text('[quote=' . $logfile . ']' . $contents . '[/quote]', true, false, true); } } unset($archive); } rcms_showAdminMessage($output); } elseif (!empty($_POST['browse_archive']) && !empty($_POST['browse'])) { $frm = new InputForm('', 'post', '<<< ' . __('Back')); $frm->show(); $_POST['browse'] = basename($_POST['browse']); if (is_readable($system->logging . $_POST['browse'])) { $archive = new tar(); $archive->openTAR($system->logging . $_POST['browse']); $frm = new InputForm('', 'post', __('Show selected')); $frm->addbreak(__('Avaible logs in archive') . ' ' . $_POST['browse']); $frm->hidden('showlogs_from_archive', '1'); $frm->hidden('archive', $_POST['browse']); foreach ($archive->files as $file_data) { if (preg_match("/^((.*?)-(.*?)-(.*?))\\.log(|.gz)\$/i", $file_data['name'], $matches)) { $frm->addrow($matches[1], $frm->checkbox('viewlog[]', $file_data['name'], '')); } } $frm->show(); unset($archive); } } else { if (!empty($_POST['build_monthly'])) { $system->logMergeByMonth();
return $html; } // Include TAR Class include "tar.class.php"; // Creating a NEW Tar file $tar = new tar(); $tar->addFile("exmaple.php"); $tar->addFile("example2.php"); $tar->addFile("tar.class.php"); $tar->toTar("new.tar", FALSE); // Normal TAR // $tar->toFile("new.tgz",TRUE); // Gzipped TAR unset($tar); // Appending 2 tar files together, saving in gzipped format (Gzipping requires zlib) $tar = new tar(); $tar->openTAR("my.tar", FALSE); $tar->appendTar("another.tar", FALSE); $tar->toTar("combined.tgz", TRUE); unset($tar); // Removing 2 files from the new.tar file created above $tar = new tar(); $tar->openTar("new.tar", FALSE); $tar->removeFile("example.php"); $tar->removeFile("example2.php"); $tar->saveTar(); // Saves to currently open TAR file (In this case, new.tar) unset($tar); // Check if a TAR file contains a specific file $tar = new tar(); $tar->openTar("new.tar", FALSE); if ($tar->containsFile("tar.class.php")) {
function procTextyleToolUserSkinImport() { if (!$this->module_srl) { exit; } // check upload if (!Context::isUploaded()) { exit; } $file = Context::get('file'); if (!is_uploaded_file($file['tmp_name'])) { exit; } if (!preg_match('/\\.(tar)$/i', $file['name'])) { exit; } $oTextyleModel =& getModel('textyle'); $skin_path = FileHandler::getRealPath($oTextyleModel->getTextylePath($this->module_srl)); $tar_file = $skin_path . 'textyle_skin.tar'; FileHandler::removeDir($skin_path); FileHandler::makeDir($skin_path); if (!move_uploaded_file($file['tmp_name'], $tar_file)) { exit; } require_once _XE_PATH_ . 'libs/tar.class.php'; $tar = new tar(); $tar->openTAR($tar_file); if (!$tar->getFile('textyle.html')) { return; } $replace_path = getNumberingPath($this->module_srl, 3); foreach ($tar->files as $key => $info) { FileHandler::writeFile($skin_path . $info['name'], str_replace('__TEXTYLE_SKIN_PATH__', $replace_path, $info['file'])); } FileHandler::removeFile($tar_file); }
require "../footer.php"; exit; } case "importqimages": if ($myrights < 100 || !$allowmacroinstall) { echo "You don't have the authority for this action"; break; } $uploaddir = rtrim(dirname(__FILE__), '/\\') . '/import/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { if (strpos($uploadfile, '.tar.gz') !== FALSE) { include "../includes/tar.class.php"; include "../includes/filehandler.php"; $tar = new tar(); $tar->openTAR($uploadfile); if ($tar->hasFiles()) { if ($GLOBALS['filehandertypecfiles'] == 's3') { $n = $tar->extractToS3("qimages", "public"); } else { $n = $tar->extractToDir("../assessment/qimages/"); } require "../header.php"; echo "<p>Extracted {$n} files. <a href=\"admin.php\">Continue</a></p>\n"; require "../footer.php"; exit; } else { require "../header.php"; echo "<p>File appears to contain nothing</p>\n"; require "../footer.php"; exit;