create() public method

--------------------------------------------------------------------------------
public create ( $p_filelist )
示例#1
2
function create_zip($themeName)
{
    $exclude_files = array('.', '..', '.svn', 'thumbs.db', '!sources', 'style.less.cache', 'bootstrap.less.cache', '.gitignore', '.git');
    $all_themes_dir = str_replace('\\', '/', get_theme_root());
    $backup_dir = str_replace('\\', '/', WP_CONTENT_DIR) . '/themes_backup';
    $zip_name = $backup_dir . "/" . $themeName . '.zip';
    $backup_date = date("F d Y");
    if (is_dir($all_themes_dir . "/" . $themeName)) {
        $file_string = scan_dir($all_themes_dir . "/" . $themeName, $exclude_files);
    }
    if (function_exists('wp_get_theme')) {
        $backup_version = wp_get_theme($themeName)->Version;
    } else {
        $backup_version = get_current_theme($themeName)->Version;
    }
    if (!is_dir($backup_dir)) {
        if (mkdir($backup_dir, 0700)) {
            $htaccess_file = fopen($backup_dir . '/.htaccess', 'a');
            $htaccess_text = 'deny from all';
            fwrite($htaccess_file, $htaccess_text);
            fclose($htaccess_file);
        }
    }
    $zip = new PclZip($zip_name);
    if ($zip->create($file_string, PCLZIP_OPT_REMOVE_PATH, $all_themes_dir . "/" . $themeName) == 0) {
        die("Error : " . $zip->errorInfo(true));
    }
    update_option($themeName . "_date_backup", $backup_date, '', 'yes');
    update_option($themeName . "_version_backup", $backup_version, '', 'yes');
    echo $backup_date . "," . $backup_version;
}
示例#2
0
function zip_go()
{
    global $list, $options;
    $saveTo = realpath($options['download_dir']) . '/';
    $_POST["archive"] = strlen(trim(urldecode($_POST["archive"]))) > 4 && substr(trim(urldecode($_POST["archive"])), -4) == ".zip" ? trim(urldecode($_POST["archive"])) : "archive.zip";
    $_POST["archive"] = $saveTo . basename($_POST["archive"]);
    for ($i = 0; $i < count($_POST["files"]); $i++) {
        $files[] = $list[$_POST["files"][$i]];
    }
    foreach ($files as $file) {
        $CurrDir = ROOT_DIR;
        $inCurrDir = stristr(dirname($file["name"]), $CurrDir) ? TRUE : FALSE;
        if ($inCurrDir) {
            $add_files[] = substr($file["name"], strlen($CurrDir) + 1);
        }
    }
    require_once CLASS_DIR . "pclzip.php";
    $archive = new PclZip($_POST["archive"]);
    $no_compression = $options['disable_archive_compression'] || isset($_POST["no_compression"]);
    if (file_exists($_POST["archive"])) {
        if ($no_compression) {
            $v_list = $archive->add($add_files, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_NO_COMPRESSION);
        } else {
            $v_list = $archive->add($add_files, PCLZIP_OPT_REMOVE_ALL_PATH);
        }
    } else {
        if ($no_compression) {
            $v_list = $archive->create($add_files, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_NO_COMPRESSION);
        } else {
            $v_list = $archive->create($add_files, PCLZIP_OPT_REMOVE_ALL_PATH);
        }
    }
    if ($v_list == 0) {
        echo "Error: " . $archive->errorInfo(true) . "<br /><br />";
        return;
    } else {
        echo "Archive <b>" . $_POST["archive"] . "</b> successfully created!<br /><br />";
    }
    if (is_file($_POST['archive'])) {
        $time = filemtime($_POST['archive']);
        while (isset($list[$time])) {
            $time++;
        }
        $list[$time] = array("name" => $_POST['archive'], "size" => bytesToKbOrMbOrGb(filesize($_POST['archive'])), "date" => $time);
        if (!updateListInFile($list)) {
            echo lang(146) . "<br /><br />";
        }
    }
}
示例#3
0
 /**
  * Exports a template
  *
  * @access public
  * @param string $templatename
  * @return void
  */
 public function templatezip($templatename)
 {
     global $oEditedTemplate;
     if (!Permission::model()->hasGlobalPermission('templates', 'export')) {
         die('No permission');
     }
     $templatedir = $oEditedTemplate->viewPath . DIRECTORY_SEPARATOR;
     $tempdir = Yii::app()->getConfig('tempdir');
     $zipfile = "{$tempdir}/{$templatename}.zip";
     Yii::app()->loadLibrary('admin.pclzip');
     $zip = new PclZip($zipfile);
     $zip->create($templatedir, PCLZIP_OPT_REMOVE_PATH, $oEditedTemplate->viewPath);
     if (is_file($zipfile)) {
         // Send the file for download!
         header("Pragma: public");
         header("Expires: 0");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Content-Type: application/force-download");
         header("Content-Disposition: attachment; filename={$templatename}.zip");
         header("Content-Description: File Transfer");
         @readfile($zipfile);
         // Delete the temporary file
         unlink($zipfile);
     }
 }
示例#4
0
 /**
  * Creates a compressed cache file for the chapter
  * 
  * @author Woxxy
  * @return url to compressed file
  */
 function compress($chapter)
 {
     $chapter->get_comic();
     $chapter->get_pages();
     $files = array();
     $this->where('chapter_id', $chapter->id)->get();
     if ($this->result_count() == 0 || !file_exists("content/comics/" . $chapter->comic->directory() . "/" . $chapter->directory() . "/" . $this->filename)) {
         $this->remove_old();
         $CI =& get_instance();
         require_once FCPATH . 'assets/pclzip/pclzip.lib.php';
         $filename = $this->filename_compressed($chapter);
         $archive = new PclZip("content/comics/" . $chapter->comic->directory() . "/" . $chapter->directory() . "/" . $filename . '.zip');
         $filearray = array();
         foreach ($chapter->pages as $page) {
             $filearray[] = "content/comics/" . $chapter->comic->directory() . "/" . $chapter->directory() . "/" . $page["filename"];
         }
         $v_list = $archive->create(implode(',', $filearray), PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_ADD_PATH, $filename, PCLZIP_OPT_NO_COMPRESSION);
         $this->chapter_id = $chapter->id;
         $this->filename = $filename . '.zip';
         $this->size = filesize("content/comics/" . $chapter->comic->directory() . "/" . $chapter->directory() . "/" . $filename . '.zip');
         $this->lastdownload = date('Y-m-d H:i:s', time());
         $this->save();
     } else {
         $this->lastdownload = date('Y-m-d H:i:s', time());
         $this->save();
     }
     return array("url" => site_url() . "content/comics/" . $chapter->comic->directory() . "/" . $chapter->directory() . "/" . urlencode($this->filename), "server_path" => FCPATH . "content/comics/" . $chapter->comic->directory() . "/" . $chapter->directory() . "/" . $this->filename);
 }
function bps_Zip_CC_Master_File()
{
    // Use ZipArchive
    if (class_exists('ZipArchive')) {
        $zip = new ZipArchive();
        $filename = WP_PLUGIN_DIR . '/bulletproof-security/admin/core/cc-master.zip';
        if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
            exit("Error: Cannot Open {$filename}\n");
        }
        $zip->addFile(WP_PLUGIN_DIR . '/bulletproof-security/admin/core/cc-master.txt', "cc-master.txt");
        $zip->close();
        return true;
    } else {
        // Use PclZip
        define('PCLZIP_TEMPORARY_DIR', WP_PLUGIN_DIR . '/bulletproof-security/admin/core/');
        require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
        if (ini_get('mbstring.func_overload') && function_exists('mb_internal_encoding')) {
            $previous_encoding = mb_internal_encoding();
            mb_internal_encoding('ISO-8859-1');
        }
        $archive = new PclZip(WP_PLUGIN_DIR . '/bulletproof-security/admin/core/cc-master.zip');
        $v_list = $archive->create(WP_PLUGIN_DIR . '/bulletproof-security/admin/core/cc-master.txt', PCLZIP_OPT_REMOVE_PATH, WP_PLUGIN_DIR . '/bulletproof-security/admin/core/');
        return true;
        if ($v_list == 0) {
            die("Error : " . $archive->errorInfo(true));
            return false;
        }
    }
}
示例#6
0
 function toSCO()
 {
     $deck_id = $_GET['deck_id'];
     if (isset($_GET['format'])) {
         $format = $_GET['format'];
     } else {
         $format = 'scorm2004_3rd';
     }
     $scorm = new Scorm();
     $scorm->create($deck_id, $format);
     $deck_name = $scorm->root_deck_name;
     $archive = new PclZip($deck_name . '.zip');
     //adding sco universal metadata
     $v_list = $archive->create(ROOT . DS . 'libraries' . DS . 'backend' . DS . $format, PCLZIP_OPT_REMOVE_PATH, ROOT . DS . 'libraries' . DS . 'backend' . DS . $format, PCLZIP_OPT_ADD_TEMP_FILE_ON);
     if ($v_list == 0) {
         die("Error : " . $archive->errorInfo(true));
     }
     //adding sco from tmp
     $v_list = $archive->add(ROOT . DS . 'tmp' . DS . $deck_name, PCLZIP_OPT_REMOVE_PATH, ROOT . DS . 'tmp' . DS . $deck_name, PCLZIP_OPT_ADD_TEMP_FILE_ON);
     if ($v_list == 0) {
         die("Error : " . $archive->errorInfo(true));
     }
     $archive->force_download();
     chmod(ROOT . DS . $deck_name . '.zip', 0777);
     unlink(ROOT . DS . $deck_name . '.zip');
     $this->RemoveDir(ROOT . DS . 'tmp' . DS . $deck_name);
 }
示例#7
0
 function export()
 {
     header("Content-type: text/html; charset=utf-8");
     ob_end_clean();
     //在循环输出前,要关闭输出缓冲区
     echo str_pad('', 1024);
     //浏览器在接受输出一定长度内容之前不会显示缓冲输出
     echo '<h1>开始导出!</h1><hr/><h3>删除初始文件</h3><hr/>';
     flush();
     del_dir($this->path_to);
     echo '删除完成!<br/><h3>删除成功,开始编译less</h3><hr/>';
     flush();
     //$this->_less();
     echo '编译成功!<br/><h3>开始复制文件</h3><hr/>';
     flush();
     $this->_fileInit();
     echo '复制成功!<br/><h3>删除开发相关文件</h3><hr/>';
     flush();
     $this->_remove();
     echo '删除成功!<br/><h3>开始替换模板种less相关内容</h3><hr/>';
     flush();
     $this->_fileReplace();
     echo '替换成功!<br/><h3>打包程序</h3><hr/>';
     flush();
     load_class('pclzip');
     ini_set('memory_limit', '2028M');
     //2G;
     $archive = new PclZip($this->zip_to);
     $v_list = $archive->create($this->path_to, PCLZIP_OPT_REMOVE_PATH, $this->path_to);
     echo '打包成功!<br/><h3>初始化配置文件</h3><hr/>';
     flush();
     $this->_initUser();
     echo '更新成功!<br/><h1>导出处理完成!^_^</h1>';
     flush();
 }
示例#8
0
 /**
  * 数据库备份
  */
 public function backup()
 {
     set_time_limit(0);
     $data = array();
     if ($_POST) {
         $backup_dir = BASEPATH . '../cache/backup/';
         if (!is_dir($backup_dir)) {
             mkdir($backup_dir, '0777', true);
         }
         include dirname(__FILE__) . '/../../config/config.db.php';
         $cfg = $db[$db['active_group']];
         $is_export_student = intval($this->input->post('is_export_student'));
         $sql_file = DbmanageModel::backupTables($cfg['database'], $backup_dir, array('*'), $is_export_student);
         if (file_exists($backup_dir . $sql_file)) {
             require_once APPPATH . 'libraries/Pclzip.php';
             $save_file = $backup_dir . "/zmte_database.zip";
             if (is_file($save_file)) {
                 @unlink($save_file);
             }
             $archive = new PclZip($save_file);
             //将文件进行压缩
             $archive->create($backup_dir . $sql_file, PCLZIP_OPT_REMOVE_ALL_PATH);
             @unlink($backup_dir . $sql_file);
             Func::dumpFile('application/zip', $save_file, 'zmte_database_' . date('YmdHis') . '.zip');
             @unlink($save_file);
             redirect('/admin/dbmanage/backup');
         } else {
             message('数据库备份失败,请稍后重试!');
         }
     } else {
         $this->load->view('dbmanage/backup', $data);
     }
 }
示例#9
0
 /**
  * Creates a compressed cache file for the chapter
  *
  * @author Woxxy
  * @return url to compressed file
  */
 function compress($comic, $language = 'en', $volume = null, $chapter = null, $subchapter = 0)
 {
     require_once FCPATH . 'assets/pclzip/pclzip.lib.php';
     $files = array();
     if (get_setting('fs_dl_volume_enabled') && $volume !== null && $chapter === null) {
         if ($volume == 0) {
             show_404();
         }
         $chapters = new Chapter();
         $chapters->where('comic_id', $comic->id)->where('volume', $volume)->order_by('volume', 'asc')->order_by('chapter', 'asc')->order_by('subchapter', 'asc')->get();
         if ($chapters->result_count() == 0) {
             show_404();
         }
         $volume_id = $volume;
         $chapter_id = $chapters->id;
         $filepath = $comic->directory();
         $filename = $this->filename_chapters_compressed($chapters);
         foreach ($chapters as $chaptere) {
             $pages = new Page();
             $pages->where('chapter_id', $chaptere->id)->get();
             foreach ($pages as $page) {
                 $files[] = array(PCLZIP_ATT_FILE_NAME => 'content/comics/' . $comic->directory() . '/' . $chaptere->directory() . '/' . $page->filename, PCLZIP_ATT_FILE_NEW_FULL_NAME => $this->filename_chapter_compressed($chaptere) . '/' . $page->filename);
             }
         }
     } else {
         $chaptere = new Chapter();
         $chaptere->where('comic_id', $comic->id)->where('language', $language)->where('volume', $volume)->where('chapter', $chapter)->where('subchapter', $subchapter);
         $chaptere->get();
         if ($chaptere->result_count() == 0) {
             show_404();
         }
         $volume_id = 0;
         $chapter_id = $chaptere->id;
         $filepath = $comic->directory() . '/' . $chaptere->directory();
         $filename = $this->filename_chapter_compressed($chaptere);
         $pages = new Page();
         $pages->where('chapter_id', $chaptere->id)->get();
         foreach ($pages as $page) {
             $files[] = 'content/comics/' . $comic->directory() . '/' . $chaptere->directory() . '/' . $page->filename;
         }
     }
     $this->where('comic_id', $comic->id)->where('volume_id', $volume_id)->where('chapter_id', $chapter_id)->get();
     if ($this->result_count() == 0 || !file_exists('content/comics/' . $filepath . '/' . $this->filename)) {
         $this->remove_old();
         $archive = new PclZip('content/comics/' . $filepath . '/' . $filename . '.zip');
         $archive->create($files, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_NO_COMPRESSION);
         $this->comic_id = $comic->id;
         $this->volume_id = $volume_id;
         $this->chapter_id = $chapter_id;
         $this->filename = $filename . '.zip';
         $this->size = filesize('content/comics/' . $filepath . '/' . $filename . '.zip');
         $this->lastdownload = date('Y-m-d H:i:s', time());
         $this->save();
     } else {
         $this->lastdownload = date('Y-m-d H:i:s', time());
         $this->save();
     }
     return array("url" => site_url() . 'content/comics/' . $filepath . '/' . urlencode($this->filename), "server_path" => FCPATH . 'content/comics/' . $filepath . '/' . $this->filename);
 }
function zip_dir($zip_dir, $zip_archive)
{
    $archive = new PclZip("{$zip_archive}");
    $v_list = $archive->create("{$zip_dir}");
    if ($v_list == 0) {
        die("Error: " . $archive->errorInfo(true));
    }
}
示例#11
0
文件: zip.php 项目: 4bs4/marifa
 /**
  * Creamos un archivo zip con la lista de archivo enviados.
  * @param string $file Archivo donde colocar la compresión.
  * @param string $base_path Path base a utilizar en la compresión zip.
  * @param array|string $files Arreglo de archivos o directorio donde se
  * encuentran los archivos a comprimir.
  * @return bool
  */
 public function compress($file, $base_path, $files)
 {
     $archive = new PclZip($file);
     if ($archive->create($files, PCLZIP_OPT_REMOVE_PATH, $base_path)) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
示例#12
0
 /**
  * zip directory
  * @param string $dir directory to zip
  * @param string $output output zip file
  * @example $com->ZipDir('../libs', './sample.zip');
  */
 public function ZipDir($dir, $output)
 {
     include_once 'external/pclzip.lib.php';
     $archive = new PclZip($output);
     $v_list = $archive->create($dir, PCLZIP_OPT_REMOVE_PATH, $dir);
     if ($v_list == 0) {
         die("Error : " . $archive->errorInfo(true));
     }
 }
示例#13
0
 /**
  * @param $sourceFolder
  * @param $destZip
  * @return bool
  */
 public function zip($sourceFolder, $destZip)
 {
     $zip = new \PclZip($destZip);
     $result = $zip->create($sourceFolder, PCLZIP_OPT_REMOVE_PATH, $sourceFolder);
     if ($result == 0) {
         Craft::log('Unable to create zip file: ' . $destZip, LogLevel::Error);
         return false;
     }
     return true;
 }
示例#14
0
 /**
  * Функция делает бекап всех файлов скрипта
  * Для исключения файлов из архива необходимо прописать их в свойство backup::$arrExcept (по умолчанию в нем array('updates', 'updates/backups'))
  * 
  * @return bool
  */
 static function backupSite()
 {
     function except($p_event, &$p_header)
     {
         return backup::skipAddingFilesToArchive($p_event, $p_header);
     }
     $file = CONF_BACKUPS_PATH_TO_FILES . terms::currentDate() . '_site_revision_' . CONF_INFO_SCRIPT_REVISION . '.zip';
     file_exists($file) ? unlink($file) : null;
     $zip = new PclZip($file);
     return !$zip->create(CONF_ROOT_DIR, PCLZIP_OPT_REMOVE_PATH, CONF_ROOT_DIR, PCLZIP_CB_PRE_ADD, 'except') ? $zip->errorInfo(true) : true;
 }
示例#15
0
 function zip_dir($zip_dir, $zip_archive)
 {
     $archive = new PclZip($zip_archive);
     $v_list = $archive->create($zip_dir);
     if ($v_list == 0) {
         if (!defined('SUGAR_PHPUNIT_RUNNER')) {
             die("Error: " . $archive->errorInfo(true));
         }
         return false;
     }
 }
示例#16
0
 public function zip()
 {
     require_once APP_SITE_PATH . '/plugins/pclzip/pclzip.lib.php';
     $zipFile = TEMP_PATH . "/test.zip";
     $pclZip = new PclZip($zipFile);
     //压缩,排除myf目录以上的所有目录
     $res = $pclZip->create(APP_SYS_PATH, PCLZIP_OPT_REMOVE_PATH, dirname(APP_SYS_PATH));
     //解压缩到指定的目录
     $extRes = $pclZip->extract(PCLZIP_OPT_PATH, TEMP_PATH . "/test/");
     dump($extRes);
 }
示例#17
0
 function zipFile($filename)
 {
     $zip_filename = $filename . '.zip';
     $zip = new PclZip($filename . '.zip');
     $result = $zip->create($filename, PCLZIP_OPT_REMOVE_ALL_PATH);
     if ($result == 0) {
         return false;
     } else {
         @unlink($this->_tmp_file);
         $this->_tmp_file = $zip_filename;
     }
 }
 /**
  * 
  * Creates a backup file
  * @param bool $backup_all whether to include customizations to Perch
  * @return a zip file
  */
 public function build($backup_type = 'all', $mysqldump_path = false)
 {
     include 'pclzip.lib.php';
     $zipfolder = 'backup';
     $zipfile = strtolower('website-backup-' . date('d-M-Y') . '.zip');
     $file = $zipfolder . DIRECTORY_SEPARATOR . $zipfile;
     //create zip
     $zip = new PclZip($file);
     $files = array();
     if ($this->can_mysqldump($mysqldump_path)) {
         //generate db dump
         exec($mysqldump_path . ' --opt --host=' . PERCH_DB_SERVER . ' --user='******' --password='******' ' . PERCH_DB_DATABASE . ' > backup/backup.sql');
         //add to zip
         $files[] = 'backup/backup.sql';
     }
     if ($backup_type == 'resources') {
         //get resources folder and add to zip
         $files[] = PERCH_PATH . '/resources';
         //if backupAll
     } elseif ($backup_type == 'custom') {
         //get resources folder and add to zip
         $files[] = PERCH_PATH . '/resources';
         //get templates
         $files[] = PERCH_PATH . '/templates';
         //get addons
         $files = $this->_get_addons($files);
         //get config
         $files[] = PERCH_PATH . '/config';
     } elseif ($backup_type == 'all') {
         $files[] = PERCH_PATH;
     }
     //die('<pre>'.print_r($files, true).'</pre>');
     //return zip
     if ($zip->create($files, PCLZIP_OPT_REMOVE_PATH, PERCH_PATH, PCLZIP_OPT_ADD_PATH, 'perch_backup') == 0) {
         if (file_exists('backup/backup.sql')) {
             unlink('backup/backup.sql');
         }
         echo $zip->errorInfo();
         exit;
     } else {
         header("Content-type:application/x-zip-compressed");
         header("Content-disposition:attachment;filename=" . $zipfile);
         readfile($file);
         //delete zip file
         unlink($file);
         //remove the sql file if it exists
         if (file_exists('backup/backup.sql')) {
             unlink('backup/backup.sql');
         }
         exit;
     }
 }
示例#19
0
function getWebsiteZip($siteid)
{
    createWebsite($siteid);
    //change so the zip filename contains the website number
    include_once 'pclzip.lib.php';
    $archive = new PclZip('content/' . szName() . '-' . $siteid . '.zip');
    $v_list = $archive->create('content/' . $siteid, PCLZIP_OPT_REMOVE_PATH, 'content/');
    if ($v_list == 0) {
        die("Error : " . $archive->errorInfo(true));
    }
    header("Content-type: application/octet-stream");
    header("Content-disposition: attachment; filename=" . szName() . "-" . $siteid . ".zip");
    readfile('content/' . szName() . '-' . $siteid . '.zip');
    unlink('content/' . szName() . '-' . $siteid . '.zip');
}
示例#20
0
/**
 * 压缩文件为zip档案
 * 
 * zip('压缩包文件名全名',array('要压缩的文件'=>'在压缩包中的新路径'));
 * 
 * zip('test.zip',array('jquery-1.11.1.min.js'=>'js/jquery'));
 * 
 * zip('test.zip',array('jquery-1.11.1.min.js','jquery-1.8.3.min.js'));
 * 
 * zip('test.zip','jquery-1.11.1.min.js');
 * @param string $zip 要生成的zip文件名
 * @param array $files 要包含的文件
 * @return bool/string
 */
function zip($zip, $files = null)
{
    $dir = realpath(dirname($zip));
    if (is_file($zip)) {
        //echo "$zip exists,it will be overwritten\r\n<br />";
    } elseif (!is_dir($dir)) {
        if (is_dir(mk_dir($dir))) {
            die("{$dir} cannot create or unwritable");
        }
    }
    $archive = new PclZip($zip);
    $errors = array();
    $v_list = $archive->create('');
    if ($v_list == 0) {
        $errors[0] = $archive->errorInfo(true);
    }
    if ($files) {
        $files = (array) $files;
        foreach ($files as $file_key => $file_value) {
            if (is_string($file_key) && strlen($file_key)) {
                $in_zip_path = $file_value;
                $file = $file_key;
            } else {
                $in_zip_path = null;
                $file = $file_value;
            }
            //var_dump($file);
            if (file_exists($file)) {
                //var_dump($file);
                $file = realpath($file);
                $file_path = dirname($file);
                //var_dump($file_path);
                if ($in_zip_path) {
                    $v_list = $archive->add($file, PCLZIP_OPT_REMOVE_PATH, $file_path, PCLZIP_OPT_ADD_PATH, $in_zip_path);
                } else {
                    $v_list = $archive->add($file, PCLZIP_OPT_REMOVE_PATH, $file_path);
                }
                if ($v_list == 0) {
                    $errors[$file] = $archive->errorInfo(true);
                }
            }
        }
    }
    if ($errors && FUN_DEBUG) {
        echo implode("\r\n<br />", $errors) . "\r\n<br />";
    }
    return is_file($zip) ? $zip : false;
}
示例#21
0
function create_album($id, $sizes)
{
    global $params;
    $album_path = album_dir($id);
    if (is_dir(album_dir($id))) {
        //--Create configuration file
        if (!file_exists(album_dir($id) . "info.yml")) {
            // There could be more parameters if necessary
            $info_yaml = Spyc::YAMLDump(array('album_title' => $params['album'], 'album_description' => ''));
            if (!($fp = fopen(album_dir($id) . 'info.yml', 'a'))) {
                $params['flash'] = 'Album info file could not be created in <code>' . album_dir($id) . 'info.yml</code>.';
                render('error');
            }
            if (!fwrite($fp, $info_yaml)) {
                $params['flash'] = 'Could not write to file <code>' . album_dir($id) . 'info.yml</code>.';
                render('error');
            }
            fclose($fp);
        }
        $originals = get_images(album_dir($id));
        //--Create ZIP-Archive to download
        //$zip = new PclZip('archive.zip');
        foreach ($originals as $image) {
            $images[] = album_dir($id) . $image;
        }
        $zip = new PclZip(album_dir($id) . 'archive.zip');
        $test = $zip->create($images, PCLZIP_OPT_REMOVE_ALL_PATH);
        if ($test == 0) {
            die("Error: " . $zip->errorInfo(true));
        }
        //--Resize images
        foreach ($sizes as $size_name => $size_pixels) {
            $resized_album_path = album_dir($id, $size_name);
            if (!is_dir($resized_album_path)) {
                mkdir($resized_album_path, 0755);
            }
            foreach ($originals as $photo) {
                scale(album_dir($id) . $photo, "{$resized_album_path}/{$photo}", $size_pixels);
            }
        }
    } else {
        $params['flash'] = "Resizing the images in <code>{$album_path}</code> failed. Could there be a permission problem?";
        render('error');
        exit;
    }
}
示例#22
0
function PclZip_test()
{
    $zip = new PclZip('data.zip');
    $zip->create('sql-dfdata.txt');
    if (!is_file('data.zip')) {
        return false;
    }
    $zip->extract(PCLZIP_OPT_PATH, './_data');
    if (!is_file('./_data/sql-dfdata.txt')) {
        return false;
    }
    $content = File::read_file('./_data/sql-dfdata.txt');
    if (empty($content)) {
        return false;
    }
    return true;
}
示例#23
0
function cherry_plugin_export_content()
{
    $exclude_files = array('xml', 'json');
    /**
     * Filters folders to exclude from export parser
     * @var array
     */
    $exclude_folder = apply_filters('cherry_export_exclude_folders', array('woocommerce_uploads', 'wc-logs'));
    $response = array('what' => 'status', 'action' => 'export_content', 'id' => '1', 'data' => __('Export content done', CHERRY_PLUGIN_DOMAIN));
    $response_file = array('what' => 'file', 'action' => 'export_content', 'id' => '2');
    $zip_name = UPLOAD_BASE_DIR . '/sample_data.zip';
    cherry_plugin_delete_file($zip_name);
    if (is_dir(UPLOAD_BASE_DIR)) {
        $file_string = cherry_plugin_scan_dir(UPLOAD_BASE_DIR, $exclude_folder, $exclude_files);
    }
    $zip = new PclZip($zip_name);
    $result = $zip->create($file_string, PCLZIP_OPT_REMOVE_ALL_PATH);
    //export json
    $json_file = cherry_plugin_export_json();
    if (is_wp_error($json_file)) {
        $response['data'] = "Error : " . $json_file->get_error_message();
    } else {
        $zip->add($json_file, PCLZIP_OPT_REMOVE_ALL_PATH);
        cherry_plugin_delete_file($json_file);
    }
    //export xml
    $xml_file = cherry_plugin_export_xml();
    if (is_wp_error($xml_file)) {
        $response['data'] = "Error : " . $xml_file->get_error_message();
    } else {
        $zip->add($xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
        cherry_plugin_delete_file($xml_file);
    }
    $nonce = wp_create_nonce('cherry_plugin_download_content');
    $file_url = add_query_arg(array('action' => 'cherry_plugin_get_export_file', 'file' => $zip_name, '_wpnonce' => $nonce), admin_url('admin-ajax.php'));
    if ($result == 0) {
        $response['data'] = "Error : " . $zip->errorInfo(true);
    } else {
        $response_file['data'] = $file_url;
    }
    $xmlResponse = new WP_Ajax_Response($response);
    $xmlResponse->add($response_file);
    $xmlResponse->send();
    exit;
}
 public function execute()
 {
     $v207e5b7e7d2b07f6b19066e8d62f4b1d = $this->getParam("target-directory");
     $vc9db0d9cdbf3dab7ae304d2b8fe6f5d8 = $this->getParam("output-file-name");
     $vc9db0d9cdbf3dab7ae304d2b8fe6f5d8 = $this->replacePlaceHolders($vc9db0d9cdbf3dab7ae304d2b8fe6f5d8);
     $this->outputFileName = $vc9db0d9cdbf3dab7ae304d2b8fe6f5d8;
     if (substr($v207e5b7e7d2b07f6b19066e8d62f4b1d, 1, 1) == ":") {
         $vba237047d6b3d7c06a2bf8b749d226b7 = substr($v207e5b7e7d2b07f6b19066e8d62f4b1d, 2);
     } else {
         $vba237047d6b3d7c06a2bf8b749d226b7 = $v207e5b7e7d2b07f6b19066e8d62f4b1d;
     }
     $vadcdbd79a8d84175c229b192aadc02f2 = new PclZip($vc9db0d9cdbf3dab7ae304d2b8fe6f5d8);
     $result = $vadcdbd79a8d84175c229b192aadc02f2->create($v207e5b7e7d2b07f6b19066e8d62f4b1d, PCLZIP_OPT_REMOVE_PATH, $vba237047d6b3d7c06a2bf8b749d226b7);
     if ($result == 0) {
         throw new Exception("Failed to create zip file: \"" . $vadcdbd79a8d84175c229b192aadc02f2->errorInfo(true) . "\"");
     }
     chmod($vc9db0d9cdbf3dab7ae304d2b8fe6f5d8, 0777);
 }
 /**
  * 打包
  * @author 郑钟良<*****@*****.**>
  */
 public function packageDownload()
 {
     $aTheme = I('theme', '', 'text');
     if ($aTheme != '') {
         $themePath = OS_THEME_PATH;
         require_once "./ThinkPHP/Library/OT/PclZip.class.php";
         $archive = new \PclZip($themePath . $aTheme . '.zip');
         $data = $archive->create($themePath . $aTheme, PCLZIP_OPT_REMOVE_PATH, $themePath);
         if ($data) {
             $this->_download($themePath . $aTheme . '.zip', $aTheme . '.zip');
             return;
         } else {
             $this->error(L('_PACKAGE_FAILURE_'));
             return;
         }
     }
     $this->error(L('_PARAMETER_ERROR_'));
 }
示例#26
0
/**
* Publishj the current result
* 
*/
function PublishResult()
{
    global $testPath;
    global $pub;
    $result;
    // build the list of files to zip
    $files;
    $dir = opendir("{$testPath}");
    while ($file = readdir($dir)) {
        if ($file != '.' && $file != '..') {
            $files[] = $testPath . "/{$file}";
        }
    }
    closedir($dir);
    if (isset($files) && count($files)) {
        // zip up the results
        $zipFile = $testPath . '/publish.zip';
        $zip = new PclZip($zipFile);
        if ($zip->create($files, PCLZIP_OPT_REMOVE_ALL_PATH) != 0) {
            // upload the actual file
            $boundary = "---------------------" . substr(md5(rand(0, 32000)), 0, 10);
            $data = "--{$boundary}\r\n";
            $data .= "Content-Disposition: form-data; name=\"file\"; filename=\"publish.zip\"\r\n";
            $data .= "Content-Type: application/zip\r\n\r\n";
            $data .= file_get_contents($zipFile);
            $data .= "\r\n--{$boundary}--\r\n";
            $params = array('http' => array('method' => 'POST', 'header' => 'Content-Type: multipart/form-data; boundary=' . $boundary, 'content' => $data));
            $ctx = stream_context_create($params);
            $url = "http://{$pub}/work/dopublish.php";
            $fp = fopen($url, 'rb', false, $ctx);
            if ($fp) {
                $response = @stream_get_contents($fp);
                if ($response && strlen($response)) {
                    $result = "http://{$pub}/result/{$response}/";
                }
            }
            // delete the zip file
            unlink($zipFile);
        }
    }
    return $result;
}
示例#27
0
 public function zip()
 {
     $dir = BASEPATH . '../81/';
     $zip_dir = BASEPATH . '../81_zip/';
     $d = @dir($dir);
     $files = array();
     if ($d) {
         while (false !== ($entry = $d->read())) {
             if ($entry != '.' && $entry != '..') {
                 $files[] = $entry;
             }
         }
         $d->close();
     }
     require_once APPPATH . 'libraries/Pclzip.php';
     foreach ($files as $file) {
         $zip = new PclZip($zip_dir . $file . '.zip');
         $zip->create($dir . $file, PCLZIP_OPT_REMOVE_ALL_PATH);
     }
 }
 function makeZip($src, $dest, $basedir)
 {
     @set_time_limit(0);
     require_once AJXP_BIN_FOLDER . "/pclzip.lib.php";
     $filePaths = array();
     foreach ($src as $item) {
         $realFile = call_user_func(array($this->wrapperClassName, "getRealFSReference"), $this->urlBase . "/" . AJXP_Utils::securePath($item));
         $basedir = trim(dirname($realFile));
         $filePaths[] = array(PCLZIP_ATT_FILE_NAME => $realFile, PCLZIP_ATT_FILE_NEW_SHORT_NAME => basename($item));
     }
     AJXP_Logger::debug("Pathes", $filePaths);
     AJXP_Logger::debug("Basedir", array($basedir));
     self::$filteringDriverInstance = $this;
     $archive = new PclZip($dest);
     $vList = $archive->create($filePaths, PCLZIP_OPT_REMOVE_PATH, $basedir, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_ADD_TEMP_FILE_ON);
     if (!$vList) {
         throw new Exception("Zip creation error : ({$dest}) " . $archive->errorInfo(true));
     }
     self::$filteringDriverInstance = null;
     return $vList;
 }
示例#29
0
 public function index()
 {
     $startime = time();
     require_once APPPATH . 'libraries/Pclzip.php';
     $zipname = "/temp/temp300.zip";
     //压缩包存储路径和名称
     $archive = new PclZip($zipname);
     //实例化这个PclZip类
     //要打包的文件或文件夹可为数组或一个字串中,用逗号分隔
     $files = array('mystuff/ad.gif', 'mystuff/alcon.doc', 'mystuff/alcon.xls', 'mystuff');
     //$files = 'mystuff/ad.gif,mystuff/alcon.doc,mystuff/alcon.xls';
     $v_list = $archive->create($files);
     //将文件进行压缩
     //$v_list = $archive->add('副本.php');
     //$v_list = $archive->create('pclzip',PCLZIP_OPT_REMOVE_PATH, "pclzip");
     if ($v_list == 0) {
         die("Error : " . $archive->errorInfo(true));
         //如果有误,提示错误信息。
     }
     echo time() - $startime;
 }
 /**
  * Exports a template
  *
  * @access public
  * @param string $templatename
  * @return void
  */
 public function templatezip($templatename)
 {
     $templatedir = getTemplatePath($templatename) . DIRECTORY_SEPARATOR;
     $tempdir = Yii::app()->getConfig('tempdir');
     $zipfile = "{$tempdir}/{$templatename}.zip";
     Yii::app()->loadLibrary('admin.pclzip.pclzip');
     $zip = new PclZip($zipfile);
     $zip->create($templatedir, PCLZIP_OPT_REMOVE_PATH, getTemplatePath($templatename));
     if (is_file($zipfile)) {
         // Send the file for download!
         header("Pragma: public");
         header("Expires: 0");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Content-Type: application/force-download");
         header("Content-Disposition: attachment; filename={$templatename}.zip");
         header("Content-Description: File Transfer");
         @readfile($zipfile);
         // Delete the temporary file
         unlink($zipfile);
     }
 }