本文整理汇总了PHP中Archive_Tar::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Archive_Tar::create方法的具体用法?PHP Archive_Tar::create怎么用?PHP Archive_Tar::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Archive_Tar
的用法示例。
在下文中一共展示了Archive_Tar::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getArchive
protected function getArchive()
{
$obj = new Archive_Tar($this->getBackupFile());
if (!is_file($this->getBackupFile())) {
$files = array();
if (!$obj->create($files)) {
echo "can't create archive";
}
}
return $obj;
}
示例2: foreach
function _generateTarFile($compress = true)
{
$pkgver = (string) $this->xml->name . '-' . (string) $this->xml->version->release;
$targetdir = !empty($this->options['targetdir']) ? $this->options['targetdir'] . DIRECTORY_SEPARATOR : '';
$tarname = $targetdir . $pkgver . ($compress ? '.tgz' : '.tar');
$tar = new Archive_Tar($tarname, $compress);
$tar->setErrorHandling(PEAR_ERROR_RETURN);
$result = $tar->create(array($this->pkginfofile));
if (PEAR::isError($result)) {
return $this->raiseError($result);
}
foreach ($this->files as $roleDir => $files) {
$result = $tar->addModify($files, $pkgver, $roleDir);
}
if (PEAR::isError($result)) {
return $this->raiseError($result);
}
$this->output .= 'Successfully created ' . $tarname . "\n";
return true;
}
示例3: lfCreateBkupData
//.........这里部分代码省略.........
if ($val == "dtb_pagelayout") {
$arrData = $objQuery->getAll("SELECT * FROM {$val} ORDER BY page_id");
} else {
$arrData = $objQuery->getAll("SELECT * FROM {$val}");
}
// CSVデータ生成
if (count($arrData) > 0) {
// カラムをCSV形式に整える
$arrKyes = SC_Utils_Ex::sfGetCommaList(array_keys($arrData[0]), false);
// データをCSV形式に整える
$data = "";
foreach ($arrData as $data_key => $data_val) {
//$val = str_replace("\"", "\\\"", $val);
$data .= $this->lfGetCSVList($arrData[$data_key]);
}
// CSV出力データ生成
$csv_data .= $val . "\r\n";
$csv_data .= $arrKyes . "\r\n";
$csv_data .= $data;
$csv_data .= "\r\n";
}
// タイムアウトを防ぐ
SC_Utils_Ex::sfFlush();
}
}
$csv_file = $bkup_dir . "bkup_data.csv";
$csv_autoinc_file = $bkup_dir . "autoinc_data.csv";
mb_internal_encoding(CHAR_CODE);
// CSV出力
// ディレクトリが存在していなければ作成する
if (!is_dir(dirname($csv_file))) {
$err = mkdir(dirname($csv_file));
}
if ($err) {
// dataをCSV出力
$fp = fopen($csv_file, "w");
if ($fp) {
if ($csv_data != "") {
$err = fwrite($fp, $csv_data);
}
fclose($fp);
}
// 自動採番をCSV出力
$fp = fopen($csv_autoinc_file, "w");
if ($fp) {
if ($csv_autoinc != "") {
$err = fwrite($fp, $csv_autoinc);
}
fclose($fp);
}
}
// 各種ファイルコピー
if ($err) {
/**
// 商品画像ファイルをコピー
// ディレクトリが存在していなければ作成する
$image_dir = $bkup_dir . "save_image/";
if (!is_dir(dirname($image_dir))) $err = mkdir(dirname($image_dir));
$copy_mess = "";
$copy_mess = SC_Utils_Ex::sfCopyDir("../../upload/save_image/",$image_dir, $copy_mess);
// テンプレートファイルをコピー
// ディレクトリが存在していなければ作成する
$templates_dir = $bkup_dir . "templates/";
if (!is_dir(dirname($templates_dir))) $err = mkdir(dirname($templates_dir));
$copy_mess = "";
$copy_mess = SC_Utils_Ex::sfCopyDir("../../user_data/templates/",$templates_dir, $copy_mess);
// インクルードファイルをコピー
// ディレクトリが存在していなければ作成する
$inc_dir = $bkup_dir . "include/";
if (!is_dir(dirname($inc_dir))) $err = mkdir(dirname($inc_dir));
$copy_mess = "";
$copy_mess = SC_Utils_Ex::sfCopyDir("../../user_data/include/",$inc_dir, $copy_mess);
// CSSファイルをコピー
// ディレクトリが存在していなければ作成する
$css_dir = $bkup_dir . "css/";
if (!is_dir(dirname($css_dir))) $err = mkdir(dirname($css_dir));
$copy_mess = "";
$copy_mess = SC_Utils_Ex::sfCopyDir("../../user_data/css/",$css_dir, $copy_mess);
**/
//圧縮フラグTRUEはgzip圧縮をおこなう
$tar = new Archive_Tar($this->bkup_dir . $bkup_name . ".tar.gz", TRUE);
//bkupフォルダに移動する
chdir($this->bkup_dir);
//圧縮をおこなう
$zip = $tar->create("./" . $bkup_name . "/");
// バックアップデータの削除
if ($zip) {
SC_Utils_Ex::sfDelFile($bkup_dir);
}
}
if (!$err) {
$arrErr['bkup_name'] = "バックアップに失敗しました。";
// バックアップデータの削除
SC_Utils_Ex::sfDelFile($bkup_dir);
}
return isset($arrErr) ? $arrErr : array();
}
示例4: archiveAndSendExportFile
public static function archiveAndSendExportFile()
{
$export_files_dir = SJB_System::getSystemSettings("EXPORT_FILES_DIRECTORY");
if (empty($export_files_dir)) {
return;
}
$archive_file_path = SJB_Path::combine($export_files_dir, "users.tar.gz");
$old_path = getcwd();
chdir($export_files_dir);
$tar = new Archive_Tar('users.tar.gz', 'gz');
$tar->create("files video pictures users.xls");
chdir($old_path);
for ($i = 0; $i < ob_get_level(); $i++) {
ob_end_clean();
}
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=users.tar.gz");
header("Content-Length: " . filesize($archive_file_path));
readfile($archive_file_path);
SJB_Filesystem::delete($export_files_dir);
}
示例5: lfCreateBkupData
/**
* バックアップファイル作成.
*
* @param string $bkup_name
* @return boolean|int 結果。true:成功 int:失敗 FIXME 本来は int ではなく、エラーメッセージを戻すべき
*/
function lfCreateBkupData($bkup_name, $work_dir)
{
$objQuery =& SC_Query_Ex::getSingletonInstance();
$csv_autoinc = '';
$arrData = array();
$success = mkdir($work_dir, 0777, true);
if (!$success) {
return __LINE__;
}
// 全テーブル取得
$arrTableList = $objQuery->listTables();
// 各テーブル情報を取得する
foreach ($arrTableList as $table) {
if ($table == 'dtb_bkup' || $table == 'mtb_zip') {
continue;
}
// dataをCSV出力
$csv_file = $work_dir . $table . '.csv';
$fp = fopen($csv_file, 'w');
if (!$fp) {
return __LINE__;
}
// 全データを取得
$sql = "SELECT * FROM {$table}";
$this->fpOutput =& $fp;
$this->first_line = true;
$success = $objQuery->doCallbackAll(array(&$this, 'cbOutputCSV'), $sql);
unset($this->fpOutput);
if ($success === false) {
return __LINE__;
}
fclose($fp);
// タイムアウトを防ぐ
SC_Utils_Ex::sfFlush();
}
// 自動採番型の構成を取得する
$csv_autoinc = $this->lfGetAutoIncrement();
$csv_autoinc_file = $work_dir . 'autoinc_data.csv';
// CSV出力
// 自動採番をCSV出力
$fp = fopen($csv_autoinc_file, 'w');
if ($fp) {
if ($csv_autoinc != '') {
$success = fwrite($fp, $csv_autoinc);
if (!$success) {
return __LINE__;
}
}
fclose($fp);
}
//圧縮フラグTRUEはgzip圧縮をおこなう
$tar = new Archive_Tar($this->bkup_dir . $bkup_name . $this->bkup_ext, TRUE);
//bkupフォルダに移動する
chdir($work_dir);
//圧縮をおこなう
$zip = $tar->create('./');
return true;
}
示例6: downloadArchiveFiles
/**
* ユーザが作成したファイルをアーカイブしダウンロードさせる
* TODO 要リファクタリング
* @param string $dir アーカイブを行なうディレクトリ
* @param string $template_code テンプレートコード
* @return boolean 成功した場合 true; 失敗した場合 false
*/
function downloadArchiveFiles($dir, $template_code)
{
// ダウンロードされるファイル名
$dlFileName = 'tpl_package_' . $template_code . '_' . date('YmdHis') . '.tar.gz';
$debug_message = $dir . ' から ' . $dlFileName . " を作成します...\n";
// ファイル一覧取得
$arrFileHash = SC_Helper_FileManager_Ex::sfGetFileList($dir);
$arrFileList = array();
foreach ($arrFileHash as $val) {
$arrFileList[] = $val['file_name'];
$debug_message .= '圧縮:' . $val['file_name'] . "\n";
}
GC_Utils_Ex::gfPrintLog($debug_message);
// ディレクトリを移動
chdir($dir);
// 圧縮をおこなう
$tar = new Archive_Tar($dlFileName, true);
if ($tar->create($arrFileList)) {
// ダウンロード用HTTPヘッダ出力
header("Content-disposition: attachment; filename={$dlFileName}");
header("Content-type: application/octet-stream; name={$dlFileName}");
header('Cache-Control: ');
header('Pragma: ');
readfile($dlFileName);
unlink($dir . '/' . $dlFileName);
return true;
} else {
return false;
}
}
示例7: createPatch
function createPatch($updatecache = false)
{
include_once "Lib/Archive/Tar.php";
include_once 'Lib/Text/Diff.php';
include_once 'Lib/Text/Diff/Renderer/unified.php';
$start = microtime(true);
$tar_object = new Archive_Tar(_bmoddir . "Data/Cache.tar");
$tar_object->setErrorHandling(PEAR_ERROR_PRINT);
$tardata = $tar_object->listContent();
$working = checkDir2("");
$fmerged = array_merge($tardata, $working);
$tarf_db = reIndexByFile($tardata);
$work_db = reIndexByFile($working);
$workidx = indexFilename($working);
$tar_idx = indexFilename($tardata);
$f_names = array_unique(array_merge($workidx, $tar_idx));
$out = "";
foreach ($f_names as $file) {
//speed optimization
if ($tarf_db[$file] && $work_db[$file] && $tarf_db[$file]["mtime"] == $work_db[$file]["mtime"] && $updatecache != true) {
continue;
}
if ($tarf_db[$file]) {
$fts1 = $tarf_db[$file]["mtime"];
$fdata = $tar_object->extractInString($file);
$lines1 = explode("\n", $fdata);
//$lines1 = file("Data/$file");
if (substr($fdata, -1, 1) == "\n") {
//$lines1[] = "";
}
} else {
$fts1 = 0;
$lines1 = array();
}
if ($work_db[$file]) {
$fts2 = $work_db[$file]["mtime"];
//$lines2 = file(_bpatdir."$file");
$filetext = file_get_contents(_bmoddir . _bpatdir . "{$file}");
$lines2 = explode("\n", $filetext);
} else {
$fts2 = 0;
$lines2 = array();
$filetext = "";
}
if (array_search($file, $workidx) === false && array_search($file, $tar_idx) !== false) {
//delted file
$out .= renderHeader($file, $fts1, $fts2);
$out .= "@@ -0,0 @@\n\n";
continue;
}
if (array_search($file, $workidx) !== false && array_search($file, $tar_idx) === false) {
//added file
}
if ($filetext == $fdata) {
continue;
}
$diff = new Text_Diff('auto', array($lines1, $lines2));
$renderer = new Text_Diff_Renderer_unified();
$render = $renderer->render($diff);
if ($render != "") {
$out .= renderHeader($file, $fts1, $fts2);
//get ts to work!
$out .= $render . "\n";
if (substr($filetext, -1, 1) != "\n") {
$out .= "\\ No newline at end of file\n\n";
}
}
}
if ($updatecache == true) {
$tar_object->create(array());
foreach ($f_names as $file) {
$tar_object->addString($file, file_get_contents(_bmoddir . _bpatdir . "{$file}"));
}
}
return array(microtime(true) - $start, $out, count($addlist));
}
示例8: download_scenarios
function download_scenarios($aSims)
{
// Define the PEAR installation path
require_once MAX_PATH . '/lib/pear/Archive/Tar.php';
$oTar = new Archive_Tar(TMP_PATH . '/scenarios.tar.gz');
$aResult = array();
$aFiles = '';
foreach ($aSims as $k => $v) {
$aData = get_simulation_file_list(SCENARIOS_DATASETS, '', false, $k);
foreach ($aData as $k1 => $v1) {
$aFiles .= FOLDER_DATA . '/' . $v1 . ' ';
}
$aFiles .= FOLDER_SAVE . '/' . $k . '.php ';
}
$tmpdir = getcwd();
chdir(SIM_PATH);
$oTar->create($aFiles);
$aResult = $oTar->listContent();
chdir($tmpdir);
return 'scenarios.tar.gz';
}
示例9: lfCreateBkupData
/**
* バックアップファイル作成.
*
* @param string $bkup_name
* @param string $work_dir
* @return boolean|int 結果。true:成功 int:失敗 FIXME 本来は int ではなく、エラーメッセージを戻すべき
*/
public function lfCreateBkupData($bkup_name, $work_dir)
{
$objQuery = Application::alias('eccube.query');
$csv_autoinc = '';
$arrData = array();
$success = mkdir($work_dir, 0777, true);
if (!$success) {
return __LINE__;
}
// 全テーブル取得
$arrTableList = $objQuery->listTables();
// 各テーブル情報を取得する
foreach ($arrTableList as $table) {
if ($table == 'dtb_bkup' || $table == 'mtb_zip') {
continue;
}
// dataをCSV出力
$csv_file = $work_dir . $table . '.csv';
$this->fpOutput = fopen($csv_file, 'w');
if (!$this->fpOutput) {
return __LINE__;
}
// 全データを取得
$sql = 'SELECT * FROM ' . $objQuery->conn->quoteIdentifier($table);
$this->output_header = true;
$success = $objQuery->doCallbackAll(array(&$this, 'cbOutputCSV'), $sql);
fclose($this->fpOutput);
if ($success === false) {
return __LINE__;
}
// タイムアウトを防ぐ
Utils::sfFlush();
}
// 自動採番型の構成を取得する
$csv_autoinc = $this->lfGetAutoIncrement();
$csv_autoinc_file = $work_dir . 'autoinc_data.csv';
// CSV出力
// 自動採番をCSV出力
$fp = fopen($csv_autoinc_file, 'w');
if ($fp) {
if ($csv_autoinc != '') {
$success = fwrite($fp, $csv_autoinc);
if (!$success) {
return __LINE__;
}
}
fclose($fp);
}
//圧縮フラグTRUEはgzip圧縮をおこなう
$tar = new Archive_Tar($this->bkup_dir . $bkup_name . $this->bkup_ext, TRUE);
//bkupフォルダに移動する
chdir($work_dir);
//圧縮をおこなう
$zip = $tar->create('./');
return true;
}
示例10: fclose
fclose($file);
// For the array
$i++;
}
// Now for the directories (and files within them) in the project
// This requires a 2nd SQL query due to the nature of creating directories in the archive, it'll get messed up if we try
// to do it with 1 loop
$query = "SELECT directories.directory, files.filename, files.extension, files.content FROM files, directories WHERE files.project_id = '{$project_id}' AND files.directory_id IS NOT NULL AND directories.directory_id = files.directory_id";
$result = mysql_query($query);
while ($fileinfo = mysql_fetch_assoc($result)) {
// If the directory doesn't exist, create it!
if (!file_exists("/tmp/" . $fileinfo['directory'] . "/")) {
mkdir("/tmp/" . $fileinfo['directory'] . "/");
}
// Build the filename
$filename = "/tmp/" . $fileinfo['directory'] . "/" . $fileinfo['filename'] . "." . $fileinfo['extension'];
// Create the file and put the information into it!
$file = fopen($filename, "w");
fwrite($file, $fileinfo['content']);
// Add the file to the array which will be loaded into the archive
$filearray[$i] = $filename;
fclose($file);
// For the array
$i++;
}
// build archive
$tar->create($filearray) or die("Could not create archive!");
// Load the tar into memory
$tar = fopen("/tmp/" . $project_id . ".tar", "r");
echo fread($tar, filesize("/tmp/" . $project_id . ".tar"));
}
示例11: microtime
echo "<pre>{$line}</pre>";
}
}
}
$superstart = microtime(true);
if (file_exists("Data/database.txt")) {
$status = file_get_contents("Data/database.txt");
} else {
$status = "";
}
include "functions.php";
$act = $_REQUEST['act'];
if ($act == "start") {
include_once "Lib/Archive/Tar.php";
$tar_object = new Archive_Tar("Data/Cache.tar");
$tar_object->create(array());
createPatch(true);
file_put_contents("Data/database.txt", "develop");
header("location: " . basename(__FILE__));
} elseif ($act == "stop") {
$dat = createPatch();
$name = $_REQUEST['pname'];
$ver = $_REQUEST['pver'];
$sum = $_REQUEST['psum'];
if ($name && $ver && $sum) {
file_put_contents("Data/database.txt", "");
$fn = "mod_" . $_REQUEST['pname'] . "_v" . $_REQUEST['pver'];
file_put_contents("Data/{$fn}.patch", "fn={$fn}\nname={$name}\nversion={$ver}\nsummary={$sum}\n\n" . $dat[1]);
echo "Done! Your package can be found in your Data/ directory as <a href='Data/{$fn}.patch'>{$fn}.patch</a>";
} else {
echo "Error! Form not complete! Please go <a href='?act=finish'>back</a> and repeat the form";
示例12: rename
$error = __("Could not create directory %s.", $incoming_pkgdir);
}
rename($pkg_dir, $incoming_pkgdir . "/" . $pkg_name);
} else {
$error = __("You are not allowed to overwrite the %h%s%h package.", "<b>", $pkg_name, "</b>");
}
}
# Re-tar the package for consistency's sake
if (!$error) {
if (!@chdir($incoming_pkgdir)) {
$error = __("Could not change directory to %s.", $incoming_pkgdir);
}
}
if (!$error) {
$tar = new Archive_Tar($pkg_name . '.tar.gz');
$create = $tar->create(array($pkg_name));
if (!$create) {
$error = __("Could not re-tar");
}
}
# Chmod files after everything has been done.
if (!$error && !chmod_group($incoming_pkgdir)) {
$error = __("Could not chmod directory %s.", $incoming_pkgdir);
}
# Whether it failed or not we can clean this out
if (file_exists($tempdir)) {
rm_rf($tempdir);
}
# Update the backend database
if (!$error) {
$dbh = db_connect();
示例13: tar
function tar($aszSource, $szDestination)
{
// include file
include COMMON . "/tar/tar.php";
// specify filename for output file
$tar = new Archive_Tar($szDestination);
// build archive
if (!$tar->create($aszSource)) {
return false;
} else {
return true;
}
}
示例14: createTar
private function createTar($backupdir, $backupLocation, $filename)
{
set_include_path(get_include_path() . PATH_SEPARATOR . Mage::getBaseDir('app') . '/code/community/Aschroder/CloudBackup/lib/');
require_once 'Archive/Tar.php';
$files = scandir($backupdir);
// remove . and ..
$files = array_diff($files, array(".", ".."));
if ($exclude = Mage::helper('cloudbackup')->getExclude()) {
$this->log("Excluding: " . $exclude);
$files = array_diff($files, explode(",", $exclude));
}
// Sometimes the store basedir will not be the CWD,
// so make our urls absolute for Archive_Tar
$abs_files = array();
foreach ($files as $file) {
$abs_files[] = $backupdir . DS . $file;
}
$this->log("Backing up: " . print_r($abs_files, true));
$tar = new Archive_Tar($backupLocation . DS . $filename, "gz");
if ($tar->create($abs_files)) {
$this->log("Backup complete");
} else {
$this->log("Could not create backup file: " . $filename);
throw new Exception("Could not write Backup Tar File: " . $filename);
}
}
示例15: packSPK
function packSPK($dir, $destPackage)
{
$oldDir = getcwd();
chdir($dir);
// echo "create $dir to $destPackage";
$package = new Archive_Tar("package.tgz", "gz");
$package->setErrorHandling(PEAR_ERROR_PRINT);
$package->create("package");
$destPackage = new Archive_Tar($destPackage);
$destPackage->create("INFO scripts package.tgz");
@unlink("package.tgz");
chdir($oldDir);
}