The public methods allow the manipulation of the archive. Attributes : Attributes must not be accessed directly. Methods : PclZip() : Object creator create() : Creates the Zip archive listContent() : List the content of the Zip archive extract() : Extract the content of the archive properties() : List the properties of the archive
Пример #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;
}
function wpd_download()
{
    if (!class_exists('PclZip')) {
        include ABSPATH . 'wp-admin/includes/class-pclzip.php';
    }
    $what = $_GET['wpd'];
    $object = $_GET['object'];
    switch ($what) {
        case 'plugin':
            if (strpos($object, '/')) {
                $object = dirname($object);
            }
            $root = WP_PLUGIN_DIR;
            break;
        case 'theme':
            $root = get_theme_root($object);
            break;
    }
    $path = $root . '/' . $object;
    $fileName = $object . '.zip';
    $archive = new PclZip($fileName);
    $archive->add($path, PCLZIP_OPT_REMOVE_PATH, $root);
    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename="' . $fileName . '"');
    readfile($fileName);
    // remove tmp zip file
    unlink($fileName);
    exit;
}
Пример #3
1
 /**
  * Unzip a file into the specified directory. Throws a RuntimeException
  * if the extraction failed.
  */
 public static function unzip($file, $to = 'cache/zip')
 {
     @ini_set('memory_limit', '256M');
     if (!is_dir($to)) {
         mkdir($to);
         chmod($to, 0777);
     }
     if (class_exists('ZipArchive')) {
         // use ZipArchive
         $zip = new ZipArchive();
         $res = $zip->open($file);
         if ($res === true) {
             $zip->extractTo($to);
             $zip->close();
         } else {
             throw new RuntimeException('Could not open zip file [ZipArchive].');
         }
     } else {
         // use PclZip
         $zip = new PclZip($file);
         if ($zip->extract(PCLZIP_OPT_PATH, $to) === 0) {
             throw new RuntimeException('Could not extract zip file [PclZip].');
         }
     }
     return true;
 }
Пример #4
0
    protected function saveUploadedFile() {
        
        $file = new Gpf_Db_File();
        $file->set('filename', $this->name);
        $file->set('filesize', $this->size);
        $file->set('filetype', $this->type);
        $file->save();
             
        $dir = new Gpf_Io_File($this->getZipFolderUrl().$file->getFileId().'/');
        if ($dir->isExists()) {
            $dir->delete();
        }
        $dir->mkdir();
        $tmpZip = new Gpf_Io_File($this->getZipFolderUrl().$file->getFileId().'/'.$file->getFileId().".zip");
        $dir->copy(new Gpf_Io_File($this->tmpName),$tmpZip);
        
        $archive = new PclZip($this->getZipFolderUrl().$file->getFileId().'/'.$file->getFileId().".zip");
        $err = $archive->extract($this->getZipFolderUrl().$file->getFileId().'/');
        if ($err <= 0) {
            throw new Gpf_Exception("code: ".$err);
        }

        $tmpZip->delete();
 
        return $file;
    }
 public function extractTextContent()
 {
     $config = KTConfig::getSingleton();
     $temp_dir = $config->get('urls/tmpDirectory');
     $docid = $this->document->getId();
     $time = 'ktindexer_openoffice_' . time() . '-' . $docid;
     $this->openxml_dir = $temp_dir . '/' . $time;
     $this->sourcefile = str_replace('\\', '/', $this->sourcefile);
     $this->openxml_dir = str_replace('\\', '/', $this->openxml_dir);
     $archive = new PclZip($this->sourcefile);
     if ($archive->extract(PCLZIP_OPT_PATH, $this->openxml_dir) == 0) {
         $this->output = _kt('Failed to extract content');
         return false;
     }
     /* *** Original code using the unzip binary ***
     		$cmd = '"' . $this->unzip . '"' . ' ' . str_replace(
     			array('{source}','{part}', '{target_dir}'),
     			array($this->sourcefile, 'content.xml',$this->openxml_dir), $this->unzip_params);
     
     		$cmd = str_replace('\\','/', $cmd);
     
      		if (!$this->exec($cmd))
     		{
     			$this->output = _kt('Failed to execute command: ') . $cmd;
     			return false;
     		}
     		*** End unzip code *** */
     $filename = $this->openxml_dir . '/content.xml';
     if (!file_exists($filename)) {
         $this->output = _kt('Failed to find file: ') . $filename;
         return false;
     }
     $result = file_put_contents($this->targetfile, $this->filter(file_get_contents($filename)));
     return $result !== false;
 }
Пример #6
0
 function guardarArchivo()
 {
     global $db, $t;
     // Copia el archivo del usuario al directorio ../files
     $tipoArchivo = $_FILES['userfile']['type'];
     //if( $tipoArchivo=="application/zip" ){
     if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
         copy($_FILES['userfile']['tmp_name'], "../facturas/facturas.zip");
         $msg[] = "<font color=green>El archivo fue cargado correctamente.</font>";
         // -------------------------------------------
         // Descomprimir los zip
         require_once '../include/pclzip.lib.php';
         $archive = new PclZip('../facturas/facturas.zip');
         //Ejecutamos la funcion extract
         //if ( $archive->extract(PCLZIP_OPT_PATH, ' ../files/facturas/',PCLZIP_OPT_REMOVE_PATH, '../files/facturas/') == 0) {
         if ($archive->extract(PCLZIP_OPT_PATH, '../facturas/', PCLZIP_OPT_REMOVE_PATH, '../facturas/') == 0) {
             die("Error : " . $archive->errorInfo(true));
         }
         // -------------------------------------------
         // Eliminar zip, ya no es necesario.
         unlink("../facturas/facturas.zip");
     } else {
         $msg[] = "<font color=red>ERROR : Possible file upload attack. Filename: " . $_FILES['userfile']['name'];
     }
     //}
     //else{
     //    $archivo = $_FILES['userfile']['name'];
     //    $msg[]= "<font color=red>ERROR : El archivo (<i>$archivo</i>) es incorrecto, debe cargar un formato ZIP, y dentro de él todas las facturas.";
     //}
     return $msg;
 }
Пример #7
0
function com_install()
{
    $database =& JFactory::getDBO();
    $path = JPATH_SITE;
    @ini_set('max_execution_time', '180');
    if (!defined('DS')) {
        define('DS', DIRECTORY_SEPARATOR);
    }
    if (file_exists($path . DS . "administrator" . DS . "includes" . DS . "pcl" . DS . "pclzip.lib.php")) {
        require_once $path . DS . "administrator" . DS . "includes" . DS . "pcl" . DS . "pclzip.lib.php";
    }
    $archivename = $path . DS . "administrator" . DS . "components" . DS . "com_sobi2" . DS . "includes" . DS . "install" . DS . "crystalsvg.zip";
    $zipfile = new PclZip($archivename);
    $zipfile->extract(PCLZIP_OPT_PATH, $path . DS . "images" . DS . "stories" . DS);
    $archivename = $path . DS . "administrator" . DS . "components" . DS . "com_sobi2" . DS . "includes" . DS . "install" . DS . "langs.zip";
    $zipfile = new PclZip($archivename);
    $zipfile->extract(PCLZIP_OPT_PATH, $path . DS . "administrator" . DS . "components" . DS . "com_sobi2" . DS . "languages" . DS);
    @unlink($path . DS . "images" . DS . "stories" . DS . "folder_add_f2.png");
    @unlink($path . DS . "images" . DS . "stories" . DS . "properties_f2.png");
    @chdir($path . DS . "images" . DS);
    @mkdir("com_sobi2", 0777);
    @chdir($path . DS . images . DS . "com_sobi2" . DS);
    @mkdir("clients", 0777);
    $m = JFactory::getApplication('site');
    $m->redirect('index2.php?option=com_sobi2&sinstall=screen', 'A instalação do SOBI2 não está concluída. Por favor terminar a primeira instalação.');
}
Пример #8
0
function extract_files($archive, $dir, $type)
{
    if ($type != "zip") {
        switch ($type) {
            case "targz":
            case "tgz":
                $cmd = which("tar") . " xfz " . escapeshellarg($archive) . " -C " . escapeshellarg($dir);
                break;
            case "tarbz2":
                $cmd = which("tar") . " xfj " . escapeshellarg($archive) . " -C " . escapeshellarg($dir);
                break;
            case "tar":
                $cmd = which("tar") . " xf " . escapeshellarg($archive) . " -C " . escapeshellarg($dir);
                break;
            case "gz":
                $cmd = which("gzip") . " -dq " . escapeshellarg($archive);
                break;
            case "bz2":
                $cmd = which("bzip2") . " -dq " . escapeshellarg($archive);
                break;
            default:
                exit;
        }
        exec($cmd . " 2>&1", $res);
        return $res;
    }
    if ($type == "zip") {
        require_once "../../lib/pclzip/pclzip.lib.php";
        $ar = new PclZip($archive);
        return $ar->extract(PCLZIP_OPT_PATH, $dir);
    }
}
Пример #9
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();
 }
Пример #10
0
 public function restore($filename)
 {
     if (!file_exists($filename)) {
         $this->pushError(sprintf(langBup::_('Filesystem backup %s does not exists'), basename($filename)));
         return false;
     }
     if (!class_exists('PclZip', false)) {
         /** @var backupBup $backup */
         $backup = $this->getModule();
         $backup->loadLibrary('pcl');
     }
     $pcl = new PclZip($filename);
     if ($files = $pcl->extract(PCLZIP_OPT_PATH, ABSPATH, PCLZIP_OPT_REPLACE_NEWER) === 0) {
         $this->pushError(langBup::_('An error has occurred while unpacking the archive'));
         return false;
     }
     unset($pcl);
     // Unpack stacks
     $stacks = glob(realpath(ABSPATH) . '/BUP*');
     if (empty($stacks)) {
         return true;
     }
     foreach ($stacks as $stack) {
         if (file_exists($stack)) {
             $pcl = new PclZip($stack);
             $pcl->extract(PCLZIP_OPT_PATH, ABSPATH, PCLZIP_OPT_REPLACE_NEWER);
             unlink($stack);
             unset($pcl);
         }
     }
     return true;
 }
 function _extract($package, $target)
 {
     // First extract files
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.archive');
     jimport('joomla.filesystem.path');
     $adapter =& JArchive::getAdapter('zip');
     $result = $adapter->extract($package, $target);
     if (!is_dir($target)) {
         require_once PATH_ROOT . 'administrator' . DS . 'includes' . DS . 'pcl' . DS . 'pclzip.lib.php';
         require_once PATH_ROOT . 'administrator' . DS . 'includes' . DS . 'pcl' . DS . 'pclerror.lib.php';
         $extract = new PclZip($package);
         if (substr(PHP_OS, 0, 3) == 'WIN') {
             if (!defined('OS_WINDOWS')) {
                 define('OS_WINDOWS', 1);
             }
         } else {
             if (!defined('OS_WINDOWS')) {
                 define('OS_WINDOWS', 0);
             }
         }
         $result = $extract->extract(PCLZIP_OPT_PATH, $target);
     }
     return $result;
 }
Пример #12
0
 public function restore_backup_file()
 {
     $data = $this->input->stream();
     if (isset($data['filename']) && !empty($data['filename'])) {
         $back_file_path = './backup/' . $data['filename'];
         if (file_exists($back_file_path)) {
             $archive = new PclZip($back_file_path);
             $row = $archive->extract(PCLZIP_OPT_PATH, "./backup/zycms");
             $row = array_shift($row);
             $extract_file_path = './' . $row['filename'];
             if (($sql_content = file_get_contents($filename = $extract_file_path)) !== false) {
                 $sql = explode("\n\n", $sql_content);
                 foreach ($sql as $key => $s) {
                     if (trim($s)) {
                         $result = $this->db->query($s);
                     }
                 }
                 unlink($extract_file_path);
                 rmdir('./backup/zycms');
                 die(json_encode(array('code' => 200, 'message' => '还原成功')));
             } else {
                 unlink($extract_file_path);
                 rmdir('./backup/zycms');
                 die(json_encode(array('code' => 403, 'message' => '还原失败')));
             }
         }
     }
 }
Пример #13
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);
 }
Пример #14
0
 /**
  * Unzip a file into the specified directory. Throws a RuntimeException
  * if the extraction failed.
  */
 public static function unzip($source, $base = null)
 {
     $base = $base ? $base : self::$folder;
     @ini_set('memory_limit', '256M');
     if (!is_dir($base)) {
         mkdir($base);
         chmod($base, 0777);
     }
     if (class_exists('ZipArchive')) {
         // use ZipArchive
         $zip = new ZipArchive();
         $res = $zip->open($source);
         if ($res === true) {
             $zip->extractTo($base);
             $zip->close();
         } else {
             throw new RuntimeException('Could not open zip file [ZipArchive].');
         }
     } else {
         // use PclZip
         $zip = new PclZip($source);
         if ($zip->extract(PCLZIP_OPT_PATH, $base) === 0) {
             throw new RuntimeException('Could not extract zip file [PclZip].');
         }
     }
     return true;
 }
Пример #15
0
 function packageUnzip($file, $target)
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.archive');
     jimport('joomla.filesystem.path');
     $extract1 =& JArchive::getAdapter('zip');
     $result = @$extract1->extract($file, $target);
     if ($result != true) {
         require_once PATH_ROOT . DS . 'administrator' . DS . 'includes' . DS . 'pcl' . DS . 'pclzip.lib.php';
         require_once PATH_ROOT . DS . 'administrator' . DS . 'includes' . DS . 'pcl' . DS . 'pclerror.lib.php';
         if (substr(PHP_OS, 0, 3) == 'WIN') {
             if (!defined('OS_WINDOWS')) {
                 define('OS_WINDOWS', 1);
             }
         } else {
             if (!defined('OS_WINDOWS')) {
                 define('OS_WINDOWS', 0);
             }
         }
         $extract2 = new PclZip($file);
         $result = @$extract2->extract(PCLZIP_OPT_PATH, $target);
     }
     unset($extract1, $extract2);
     return $result;
 }
Пример #16
0
 public function remoteinstall()
 {
     //安全验证 $this->checksafeauth();
     $url = $this->_get('url');
     $ext = strtolower(strrchr($url, '.'));
     $filepath = ltrim(strrchr($url, '/'), '/');
     if ($ext != '.zip') {
         //兼容旧版本
         $url = xbase64_decode($url);
         $ext = strtolower(strrchr($url, '.'));
         $filepath = ltrim(strrchr($url, '/'), '/');
         if ($ext != '.zip') {
             $this->error('远程文件格式必须为.zip');
         }
     }
     $content = fopen_url($url);
     if (empty($content)) {
         $this->error('远程获取文件失败!');
     }
     $filename = substr($filepath, 0, -4);
     File::write_file($filepath, $content);
     import('ORG.PclZip');
     $zip = new PclZip($filepath);
     $zip->extract(PCLZIP_OPT_PATH, './');
     @unlink($filepath);
     //删除安装文件
     $this->success('操作成功!', U('App/index'));
 }
Пример #17
0
function zip_fallback($player_package) {
  $player_found = false;
  require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
  $zip = new PclZip($player_package);
  $archive_files = $zip->extract(PCLZIP_OPT_EXTRACT_AS_STRING);
  $dir = $archive_files[0]["filename"];
  foreach($archive_files as $file) {
    $result = true;
    if ($file["filename"] == $dir . "player.swf" || $file["filename"] == $dir . "player-licensed.swf") {
      $result = @file_put_contents(LongTailFramework::getPrimaryPlayerPath(), $file["content"]);
      if (!$result) {
        return WRITE_ERROR;
      }
      $player_found = true;
    } else if ($file["filename"] == $dir . "yt.swf") {
      $result = @file_put_contents(str_replace("player.swf", "yt.swf", LongTailFramework::getPrimaryPlayerPath()), $file["content"]);
      if (!$result) {
        return WRITE_ERROR;
      }
    } else if ($file["filename"] == $dir . "jwplayer.js") {
      $result = @file_put_contents(LongTailFramework::getEmbedderPath(), $file["content"]);
      if (!$result) {
         return WRITE_ERROR;
      }
    }
  }
  if ($player_found) {
    unlink($player_package);
    return SUCCESS;
  }
  return ZIP_ERROR;
}
Пример #18
0
function bps_zip_root_htaccess_file()
{
    // Use ZipArchive
    if (class_exists('ZipArchive')) {
        $zip = new ZipArchive();
        $filename = WP_PLUGIN_DIR . '/bulletproof-security/admin/wizard/root-htaccess-file.zip';
        if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
            exit("Error: Cannot Open {$filename}\n");
        }
        $zip->addFile(ABSPATH . '.htaccess', ".htaccess");
        $zip->close();
        return true;
    } else {
        // Use PclZip
        define('PCLZIP_TEMPORARY_DIR', WP_PLUGIN_DIR . '/bulletproof-security/admin/wizard/');
        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/wizard/root-htaccess-file.zip');
        $v_list = $archive->create(ABSPATH . '.htaccess', PCLZIP_OPT_REMOVE_PATH, ABSPATH);
        return true;
        if ($v_list == 0) {
            die("Error : " . $archive->errorInfo(true));
            return false;
        }
    }
}
function themedrive_unzip($file, $dir)
{
    if (!current_user_can('edit_files')) {
        echo 'Oops, sorry you are not authorized to do this';
        return false;
    }
    if (!class_exists('PclZip')) {
        require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
    }
    $unzipArchive = new PclZip($file);
    $list = $unzipArchive->properties();
    if (!$list['nb']) {
        return false;
    }
    //echo "Number of files in archive : ".$list['nb']."<br>";
    echo "Copying the files<br>";
    $result = $unzipArchive->extract(PCLZIP_OPT_PATH, $dir);
    if ($result == 0) {
        echo 'Could not unarchive the file: ' . $unzipArchive->errorInfo(true) . ' <br />';
        return false;
    } else {
        //print_r($result);
        foreach ($result as $item) {
            if ($item['status'] != 'ok') {
                echo $item['stored_filename'] . ' ... ' . $item['status'] . '<br>';
            }
        }
        return true;
    }
}
Пример #20
0
 function unzip($fn, $to, $suffix = false)
 {
     @set_time_limit(0);
     // Unzip uses a lot of memory
     @ini_set('memory_limit', '256M');
     require_once iPATH . 'include/pclzip.class.php';
     $files = array();
     $zip = new PclZip($fn);
     // Is the archive valid?
     if (false == ($archive_files = $zip->extract(PCLZIP_OPT_EXTRACT_AS_STRING))) {
         exit("ZIP包错误");
     }
     if (0 == count($archive_files)) {
         exit("空的ZIP文件");
     }
     $path = self::path($to);
     self::mkdir($path);
     foreach ($archive_files as $file) {
         $files[] = array('filename' => $file['filename'], 'isdir' => $file['folder']);
         $folder = $file['folder'] ? $file['filename'] : dirname($file['filename']);
         self::mkdir($path . '/' . $folder);
         if (empty($file['folder'])) {
             $fp = $path . '/' . $file['filename'];
             $suffix && ($fp = $fp . '.' . $suffix);
             self::write($fp, $file['content']);
         }
     }
     return $files;
 }
Пример #21
0
 /**
  * 数据库还原
  */
 public function restore()
 {
     set_time_limit(0);
     $data = array();
     if ($_POST) {
         if (!$_FILES['db_file']) {
             message('请上传文件!');
         }
         /**
          * 上传文件
          */
         $upload_path = BASEPATH . '/../cache/backup/';
         $txt = strtolower(end(explode('.', $_FILES['db_file']['name'])));
         if (!in_array($txt, array('sql', 'zip'))) {
             message('数据文件格式不符合要求!');
         }
         $file_name = microtime(true) . '.' . $txt;
         $upload_file = $upload_path . $file_name;
         if (!is_dir($upload_path)) {
             mkdir($upload_path, '0777', true);
         }
         if (!@move_uploaded_file($_FILES['db_file']['tmp_name'], $upload_file)) {
             message('文件处理失败,请重新上传文件!');
         } else {
             if ($txt == 'zip') {
                 require_once APPPATH . 'libraries/Pclzip.php';
                 $archive = new PclZip($upload_file);
                 $list = $archive->extract(PCLZIP_OPT_BY_NAME, $upload_file . "zmte.sql", PCLZIP_OPT_EXTRACT_AS_STRING);
                 pr($list, 1);
             }
         }
     }
     $this->load->view('dbmanage/restore', $data);
 }
function rex_a22_extract_archive($file, $destFolder = null)
{
    global $REX;
    if (!$destFolder) {
        $destFolder = '../files/' . $REX['TEMP_PREFIX'] . '/addon_framework';
    }
    $archive = new PclZip($file);
    if ($archive->extract(PCLZIP_OPT_PATH, $destFolder) == 0) {
        die("Error : " . $archive->errorInfo(true));
    }
    if (($list = $archive->listContent()) == 0) {
        die("Error : " . $archive->errorInfo(true));
    }
    echo '<div style="height:200px;width:770px;overflow:auto;margin-bottom:10px;text-align:center;">';
    echo '<h3>Archiv wird extrahiert...</h3>';
    echo '<table border="1" style="margin:0 auto 0 auto;">';
    echo '<tr><th>Datei</th><th>Gr&ouml;&szlig;e</th>';
    for ($i = 0; $i < count($list); $i++) {
        echo '<tr>';
        echo '<td>' . $list[$i]['filename'] . '</td><td>' . $list[$i]['size'] . ' bytes</td>';
        echo '</tr>';
    }
    echo '</table>';
    echo '</div>';
}
Пример #23
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);
 }
Пример #24
0
 function getHeight($lat, $lon)
 {
     global $openDEMfiles, $CONF_DEMpath;
     if ($lat >= 0) {
         $latSouth = floor($lat);
         //$latNorth=$latSouth+1;
         $latD = 1 - $lat + $latSouth;
         $latStr = "N";
     } else {
         $latSouth = ceil(abs($lat));
         // $latNorth=$latSouth-1;
         $latD = -$lat - $latSouth + 1;
         $latStr = "S";
     }
     if ($lon >= 0) {
         $lonWest = floor($lon);
         //$lonEast=$lonWest+1;
         $lonD = $lon - $lonWest;
         $lonStr = "E";
     } else {
         $lonWest = ceil(abs($lon));
         //$lonEast=$lonWest-1;
         $lonD = $lonWest + $lon;
         $lonStr = "W";
     }
     // find the file to use!
     $demFile = sprintf("%s%02d%s%03d.hgt.zip", $latStr, $latSouth, $lonStr, $lonWest);
     if (!isset($openDEMfiles[$demFile])) {
         // echo "Getting DEM file: $demFile<BR>";
         if (!is_file($CONF_DEMpath . '/' . $demFile)) {
             // echo "#not found ".$CONF_DEMpath.'/'.$demFile."#";
             return 0;
         }
         require_once dirname(__FILE__) . '/lib/pclzip/pclzip.lib.php';
         $archive = new PclZip($CONF_DEMpath . '/' . $demFile);
         $list = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING);
         if ($list == 0) {
             //
             // echo "unzip error<br>";
             return 0;
             // die("Error : ".$archive->errorInfo(true));
         } else {
             //	echo $list[0]['content'];
         }
         $openDEMfiles[$demFile] = $list[0]['content'];
     }
     // find x,y inside the file
     // 1 degree is 1201 points
     $x = floor($lonD * 1201);
     $y = floor($latD * 1201);
     // point offeset in file
     $pointOffset = ($x + $y * 1201) * 2;
     // echo "$latD $lonD $x $y  $pointOffset<BR>";
     $alt = ord($openDEMfiles[$demFile][$pointOffset]) * 256 + ord($openDEMfiles[$demFile][$pointOffset + 1]);
     if ($alt > 10000) {
         $alt = 0;
     }
     return $alt;
 }
Пример #25
0
 public function upgradecoreAction()
 {
     global $log;
     @ini_set('memory_limit', '256M');
     // Must set timeout !!!!!
     if (file_exists(APPLICATION_DIRECTORY . "/Joobsbox/Temp/Core_Upgrade_Log")) {
         $log = unserialize(file_get_contents(APPLICATION_DIRECTORY . "/Joobsbox/Temp/Core_Upgrade_Log"));
     } else {
         $log = array('lastActionMessage' => $this->view->translate("Starting file download"), 'actions' => array(), 'messageLog' => array());
         $this->updateLogFile($log);
     }
     /******************* LATEST FILE DOWNLAD *******************/
     /***********************************************************/
     if (!isset($log['actions']['downloaded'])) {
         // Download file from our repository
         $client = new Zend_Http_Client($this->requestBase . '/download/core');
         try {
             $response = $client->request();
             $file = $response->getBody();
             file_put_contents(APPLICATION_DIRECTORY . '/Joobsbox/Temp/latest.zip', $file);
             $log['messageLog'][] = $this->view->translate("Downloaded latest JoobsBox archive.");
             $log['actions']['downloaded'] = true;
             $this->updateLogFile($log);
         } catch (Exception $e) {
             $this->view->coreUpgrade = false;
             $log['messageLog'][] = $this->view->translate("Couldn't connect to the JoobsBox download server. Please check connection or contact your system's administrator.");
             $log['actions']['FAILED'] = true;
             $this->updateLogFile($log);
         }
     }
     /*************************** UNZIP *************************/
     /***********************************************************/
     require_once APPLICATION_DIRECTORY . "/Joobsbox/Filesystem/Zip.php";
     if (file_exists(APPLICATION_DIRECTORY . "/Joobsbox/Temp/joobsbox")) {
         // Move to trash
         @rename(APPLICATION_DIRECTORY . "/Joobsbox/Temp/joobsbox", APPLICATION_DIRECTORY . "/Joobsbox/Temp/.Trash/joobsbox");
     }
     $archive = new PclZip(APPLICATION_DIRECTORY . '/Joobsbox/Temp/latest.zip');
     $files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING);
     if ($files) {
         $log['messageLog'][] = $this->view->translate("Unzipped latest archive.");
     } else {
         $log['messageLog'][] = $this->view->translate("An error occured while unpacking the zip file. Please try again.");
         $log['actions']['FAILED'] = true;
     }
     $this->updateLogFile($log);
     /************************ UPDATE FILES *********************/
     /***********************************************************/
     $log['messageLog'][] = $this->view->translate("Updating files...");
     if (file_exists(APPLICATION_DIRECTORY . '/Joobsbox/Temp/backup/')) {
         rename(APPLICATION_DIRECTORY . '/Joobsbox/Temp/backup/', APPLICATION_DIRECTORY . '/Joobsbox/Temp/.Trash/backup/');
     }
     mkdir(APPLICATION_DIRECTORY . '/Joobsbox/Temp/backup/');
     $log['messageLog'][] = $this->view->translate("Created main application backup location Joobsbox/Temp/backup/");
     $log['messageLog'][] = $this->view->translate("Backing up and upgrading files as needed");
     $this->updateLogFile($log);
     $this->recurseAndUpgrade(0, $files);
     die;
 }
Пример #26
0
 function install($package)
 {
     $this->init();
     $this->install_strings();
     global $wp_filesystem;
     //add_filter('upgrader_source_selection', array($this, 'check_package') );
     // $package is the path to zip file, so unzip it
     $destination = OP_LIB . 'content_layouts/working';
     // clear destination
     foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($destination, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path) {
         $path->isFile() ? unlink($path->getPathname()) : rmdir($path->getPathname());
     }
     if (class_exists('ZipArchive')) {
         $zip = new ZipArchive();
         if ($zip->open($package) === true) {
             $zip->extractTo($destination);
             $zip->close();
             echo $this->strings['process_success'];
             // install the template
             require_once OP_LIB . 'admin/install.php';
             $ins = new OptimizePress_Install();
             $this->result = $ins->add_content_templates($destination, '', '', true, false);
             // refresh everything
             $GLOBALS['op_layout_uploaded'] = true;
             echo '<script type="text/javascript">var win = window.dialogArguments || opener || parent || top; win.op_refresh_content_layouts();</script>';
         } else {
             echo $this->strings['process_failed'];
         }
     } else {
         require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
         $zip = new PclZip($package);
         $zip->extract(PCLZIP_OPT_PATH, $destination);
         echo $this->strings['process_success'];
         // install the template
         require_once OP_LIB . 'admin/install.php';
         $ins = new OptimizePress_Install();
         $this->result = $ins->add_content_templates($destination, '', '', true, false);
         // refresh everything
         $GLOBALS['op_layout_uploaded'] = true;
         echo '<script type="text/javascript">var win = window.dialogArguments || opener || parent || top; win.op_refresh_content_layouts();</script>';
     }
     /*$this->run(array(
     					'package' => $package,
     					'destination' => OP_LIB.'content_layouts/working',//rtrim(OP_ASSETS,'/'),
     					'clear_destination' => true, //Do not overwrite files.
     					'clear_working' => true,
     					//'hook_extra' => array($this,'install_content_layout')
     					));
     
     		remove_filter('upgrader_source_selection', array($this, 'check_package') );
     
     		if ( ! $this->result || is_wp_error($this->result) )
     			return $this->result;
     		*/
     // Force refresh of plugin update information
     //delete_site_transient('update_plugins');
     //remove_filter('upgrader_source_selection', array($this, 'check_package') );
     return true;
 }
Пример #27
0
 public function upload()
 {
     if (!MRights::can("upload")) {
         return $this->_noAuth("upload");
     }
     global $dir;
     $maxSize = MRoots::getMaxUploadSize();
     $maxSizeFormatted = MRoots::getMaxUploadSize(1);
     $files = $_FILES['files'];
     if (!$files) {
         $this->iframe(MText::_("up_too_large"));
         return null;
     }
     // Get the number of upload fields
     $rows = (int) MConfig::instance()->get("max_upload_fields", 6);
     // Check if empty
     $isEmpty = true;
     for ($t = 0; $t < $rows; $t++) {
         if (!empty($files["name"][$t])) {
             $isEmpty = false;
             break;
         }
     }
     $error = !$isEmpty ? null : MText::_("nouploadfilesselected");
     for ($t = 0; $t < $rows; $t++) {
         if (!empty($files["name"][$t])) {
             if ($files['size'][$t] <= $maxSize) {
                 $fileName = $dir . DS . $files['name'][$t];
                 $upload = move_uploaded_file($files['tmp_name'][$t], $fileName);
                 if (!$upload) {
                     $error .= MText::_("couldntupload") . ": " . $files['name'][$t] . "<br>";
                 } else {
                     if (isset($_REQUEST["unzip"][$t]) && !empty($_REQUEST["unzip"][$t])) {
                         $archive = new PclZip($fileName);
                         $status = $archive->extract(PCLZIP_OPT_PATH, $dir);
                         foreach ($status as $item) {
                             if ($item['status'] != "ok") {
                                 $error .= ' - <b>' . $item['stored_filename'] . ":</b> " . MText::_($item['status']) . '<br>';
                             }
                         }
                         //EOF foreach status
                         //Remove archive
                         MFile::remove($fileName);
                     }
                 }
             } else {
                 $error .= MText::_("couldntupload") . ": " . $files['name'][$t] . " -> " . MText::_("filetoolarge") . " " . $maxSizeFormatted . "<br>";
             }
         }
     }
     $template = null;
     if (file_exists(_FM_HOME_DIR . DS . 'templates' . DS . "afterupload.php")) {
         $template = _FM_HOME_DIR . DS . 'templates' . DS . "afterupload.php";
         $arg = array("dir" => $dir, "error" => $error);
         $this->view->add2Content(MTemplater::get($template, $arg));
     } else {
         $this->view->add2Content("Error: No after upload template!");
     }
 }
Пример #28
0
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));
    }
}
Пример #29
0
function cherry_unzip_backup($file, $themes_folder)
{
    $zip = new PclZip($file);
    if ($zip->extract(PCLZIP_OPT_PATH, $themes_folder) == 0) {
        die("Error : " . $zip->errorInfo(true));
    }
    echo get_option(PARENT_NAME . "_version_backup");
}
Пример #30
0
function extractEditor()
{
    $handle = new PclZip('./editor/jar/pluginwiris.zip');
    if ($handle->extract(PCLZIP_OPT_PATH, "./editor/jar/") === false) {
        return false;
    }
    return true;
}