⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 archive_tar.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 5 页
字号:
<?php/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: *//** * File::CSV * * PHP versions 4 and 5 * * Copyright (c) 1997-2008, * Vincent Blavet <vincent@phpconcept.net> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * *     * Redistributions of source code must retain the above copyright notice, *       this list of conditions and the following disclaimer. *     * Redistributions in binary form must reproduce the above copyright *       notice, this list of conditions and the following disclaimer in the *       documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * * @category    File_Formats * @package     Archive_Tar * @author      Vincent Blavet <vincent@phpconcept.net> * @copyright   1997-2008 The Authors * @license     http://www.opensource.org/licenses/bsd-license.php New BSD License * @version     CVS: $Id: Tar.php,v 1.42 2007/08/18 23:04:10 cellog Exp $ * @link        http://pear.php.net/package/Archive_Tar */// Check to ensure this file is within the rest of the frameworkdefined('JPATH_BASE') or die();jimport('pear.PEAR');define ('ARCHIVE_TAR_ATT_SEPARATOR', 90001);define ('ARCHIVE_TAR_END_BLOCK', pack("a512", ''));/*** Creates a (compressed) Tar archive** @author   Vincent Blavet <vincent@phpconcept.net>* @version  $Revision: 1.42 $* @license  http://www.opensource.org/licenses/bsd-license.php New BSD License* @package  Archive_Tar*/class Archive_Tar extends PEAR{    /**    * @var string Name of the Tar    */    var $_tarname='';    /**    * @var boolean if true, the Tar file will be gzipped    */    var $_compress=false;    /**    * @var string Type of compression : 'none', 'gz' or 'bz2'    */    var $_compress_type='none';    /**    * @var string Explode separator    */    var $_separator=' ';    /**    * @var file descriptor    */    var $_file=0;    /**    * @var string Local Tar name of a remote Tar (http:// or ftp://)    */    var $_temp_tarname='';    // {{{ constructor    /**    * Archive_Tar Class constructor. This flavour of the constructor only    * declare a new Archive_Tar object, identifying it by the name of the    * tar file.    * If the compress argument is set the tar will be read or created as a    * gzip or bz2 compressed TAR file.    *    * @param    string  $p_tarname  The name of the tar archive to create    * @param    string  $p_compress can be null, 'gz' or 'bz2'. This    *                   parameter indicates if gzip or bz2 compression    *                   is required.  For compatibility reason the    *                   boolean value 'true' means 'gz'.    * @access public    */    function Archive_Tar($p_tarname, $p_compress = null)    {        $this->PEAR();        $this->_compress = false;        $this->_compress_type = 'none';        if (($p_compress === null) || ($p_compress == '')) {            if (@file_exists($p_tarname)) {                if ($fp = @fopen($p_tarname, "rb")) {                    // look for gzip magic cookie                    $data = fread($fp, 2);                    fclose($fp);                    if ($data == "\37\213") {                        $this->_compress = true;                        $this->_compress_type = 'gz';                    // No sure it's enought for a magic code ....                    } elseif ($data == "BZ") {                        $this->_compress = true;                        $this->_compress_type = 'bz2';                    }                }            } else {                // probably a remote file or some file accessible                // through a stream interface                if (substr($p_tarname, -2) == 'gz') {                    $this->_compress = true;                    $this->_compress_type = 'gz';                } elseif ((substr($p_tarname, -3) == 'bz2') ||                          (substr($p_tarname, -2) == 'bz')) {                    $this->_compress = true;                    $this->_compress_type = 'bz2';                }            }        } else {            if (($p_compress === true) || ($p_compress == 'gz')) {                $this->_compress = true;                $this->_compress_type = 'gz';            } else if ($p_compress == 'bz2') {                $this->_compress = true;                $this->_compress_type = 'bz2';            } else {                die("Unsupported compression type '$p_compress'\n".                    "Supported types are 'gz' and 'bz2'.\n");                return false;            }        }        $this->_tarname = $p_tarname;        if ($this->_compress) { // assert zlib or bz2 extension support            if ($this->_compress_type == 'gz')                $extname = 'zlib';            else if ($this->_compress_type == 'bz2')                $extname = 'bz2';            if (!extension_loaded($extname)) {                PEAR::loadExtension($extname);            }            if (!extension_loaded($extname)) {                die("The extension '$extname' couldn't be found.\n".                    "Please make sure your version of PHP was built ".                    "with '$extname' support.\n");                return false;            }        }    }    // }}}    // {{{ destructor    function _Archive_Tar()    {        $this->_close();        // ----- Look for a local copy to delete        if ($this->_temp_tarname != '')            @unlink($this->_temp_tarname);        $this->_PEAR();    }    // }}}    // {{{ create()    /**    * This method creates the archive file and add the files / directories    * that are listed in $p_filelist.    * If a file with the same name exist and is writable, it is replaced    * by the new tar.    * The method return false and a PEAR error text.    * The $p_filelist parameter can be an array of string, each string    * representing a filename or a directory name with their path if    * needed. It can also be a single string with names separated by a    * single blank.    * For each directory added in the archive, the files and    * sub-directories are also added.    * See also createModify() method for more details.    *    * @param array  $p_filelist An array of filenames and directory names, or a	*                           single string with names separated by a single	*                           blank space.    * @return                   true on success, false on error.    * @see createModify()    * @access public    */    function create($p_filelist)    {        return $this->createModify($p_filelist, '', '');    }    // }}}    // {{{ add()    /**    * This method add the files / directories that are listed in $p_filelist in    * the archive. If the archive does not exist it is created.    * The method return false and a PEAR error text.    * The files and directories listed are only added at the end of the archive,    * even if a file with the same name is already archived.    * See also createModify() method for more details.    *    * @param array  $p_filelist An array of filenames and directory names, or a	*                           single string with names separated by a single	*                           blank space.    * @return                   true on success, false on error.    * @see createModify()    * @access public    */    function add($p_filelist)    {        return $this->addModify($p_filelist, '', '');    }    // }}}    // {{{ extract()    function extract($p_path='')    {        return $this->extractModify($p_path, '');    }    // }}}    // {{{ listContent()    function listContent()    {        $v_list_detail = array();        if ($this->_openRead()) {            if (!$this->_extractList('', $v_list_detail, "list", '', '')) {                unset($v_list_detail);                $v_list_detail = 0;            }            $this->_close();        }        return $v_list_detail;    }    // }}}    // {{{ createModify()    /**    * This method creates the archive file and add the files / directories    * that are listed in $p_filelist.    * If the file already exists and is writable, it is replaced by the    * new tar. It is a create and not an add. If the file exists and is    * read-only or is a directory it is not replaced. The method return    * false and a PEAR error text.    * The $p_filelist parameter can be an array of string, each string    * representing a filename or a directory name with their path if    * needed. It can also be a single string with names separated by a    * single blank.    * The path indicated in $p_remove_dir will be removed from the    * memorized path of each file / directory listed when this path    * exists. By default nothing is removed (empty path '')    * The path indicated in $p_add_dir will be added at the beginning of    * the memorized path of each file / directory listed. However it can    * be set to empty ''. The adding of a path is done after the removing    * of path.    * The path add/remove ability enables the user to prepare an archive    * for extraction in a different path than the origin files are.    * See also addModify() method for file adding properties.    *    * @param array  $p_filelist     An array of filenames and directory names,	*                               or a single string with names separated by	*                               a single blank space.    * @param string $p_add_dir      A string which contains a path to be added	*                               to the memorized path of each element in	*                               the list.    * @param string $p_remove_dir   A string which contains a path to be	*                               removed from the memorized path of each	*                               element in the list, when relevant.    * @return boolean               true on success, false on error.    * @access public    * @see addModify()    */    function createModify($p_filelist, $p_add_dir, $p_remove_dir='')    {        $v_result = true;        if (!$this->_openWrite())            return false;        if ($p_filelist != '') {            if (is_array($p_filelist))                $v_list = $p_filelist;            elseif (is_string($p_filelist))                $v_list = explode($this->_separator, $p_filelist);            else {                $this->_cleanFile();                $this->_error('Invalid file list');                return false;            }            $v_result = $this->_addList($v_list, $p_add_dir, $p_remove_dir);        }        if ($v_result) {            $this->_writeFooter();            $this->_close();        } else            $this->_cleanFile();        return $v_result;    }    // }}}    // {{{ addModify()    /**    * This method add the files / directories listed in $p_filelist at the    * end of the existing archive. If the archive does not yet exists it    * is created.    * The $p_filelist parameter can be an array of string, each string    * representing a filename or a directory name with their path if    * needed. It can also be a single string with names separated by a    * single blank.    * The path indicated in $p_remove_dir will be removed from the    * memorized path of each file / directory listed when this path    * exists. By default nothing is removed (empty path '')    * The path indicated in $p_add_dir will be added at the beginning of    * the memorized path of each file / directory listed. However it can    * be set to empty ''. The adding of a path is done after the removing    * of path.    * The path add/remove ability enables the user to prepare an archive    * for extraction in a different path than the origin files are.    * If a file/dir is already in the archive it will only be added at the    * end of the archive. There is no update of the existing archived    * file/dir. However while extracting the archive, the last file will    * replace the first one. This results in a none optimization of the    * archive size.    * If a file/dir does not exist the file/dir is ignored. However an    * error text is send to PEAR error.    * If a file/dir is not readable the file/dir is ignored. However an    * error text is send to PEAR error.    *    * @param array      $p_filelist     An array of filenames and directory	*                                   names, or a single string with names	*                                   separated by a single blank space.    * @param string     $p_add_dir      A string which contains a path to be	*                                   added to the memorized path of each	*                                   element in the list.    * @param string     $p_remove_dir   A string which contains a path to be	*                                   removed from the memorized path of	*                                   each element in the list, when    *                                   relevant.    * @return                           true on success, false on error.    * @access public    */    function addModify($p_filelist, $p_add_dir, $p_remove_dir='')    {        $v_result = true;        if (!$this->_isArchive())            $v_result = $this->createModify($p_filelist, $p_add_dir,			                                $p_remove_dir);        else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -