点击回首页
我的浏览记录 | | 帮助?
当前位置:
首页>> 企业应用>> 新翔网络OA系统V1.0>> 源文件浏览
[商业版 200RMB] WebForm,下载次数:1 次 | 关键字: PHP MYSQL OA 办公 网络办公

源码截图

源码目录树

;
当前路径:Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php
<?php
// --------------------------------------------------------------------------------
// PhpConcept Library - Zip Module 2.8.2
// --------------------------------------------------------------------------------
// License GNU/LGPL - Vincent Blavet - August 2009
// http://www.phpconcept.net
// --------------------------------------------------------------------------------
//
// Presentation :
//     PclZip is a PHP library that manage ZIP archives.
//     So far tests show that archives generated by PclZip are readable by
//     WinZip application and other tools.
//
// Description :
//     See readme.txt and http://www.phpconcept.net
//
// Warning :
//     This library and the associated files are non commercial, non professional
//     work.
//     It should not have unexpected results. However if any damage is caused by
//     this software the author can not be responsible.
//     The use of this software is at the risk of the user.
//
// --------------------------------------------------------------------------------
// $Id: pclzip.lib.php,v 1.60 2009/09/30 21:01:04 vblavet Exp $
// --------------------------------------------------------------------------------

// ----- Constants
if (!defined('PCLZIP_READ_BLOCK_SIZE')) {
    define('PCLZIP_READ_BLOCK_SIZE', 2048);
}

// ----- File list separator
// In version 1.x of PclZip, the separator for file list is a space
// (which is not a very smart choice, specifically for windows paths !).
// A better separator should be a comma (,). This constant gives you the
// abilty to change that.
// However notice that changing this value, may have impact on existing
// scripts, using space separated filenames.
// Recommanded values for compatibility with older versions :
//define('PCLZIP_SEPARATOR', ' ');
// Recommanded values for smart separation of filenames.
if (!defined('PCLZIP_SEPARATOR')) {
    define('PCLZIP_SEPARATOR', ',');
}

// ----- Error configuration
// 0 : PclZip Class integrated error handling
// 1 : PclError external library error handling. By enabling this
//         you must ensure that you have included PclError library.
// [2,...] : reserved for futur use
if (!defined('PCLZIP_ERROR_EXTERNAL')) {
    define('PCLZIP_ERROR_EXTERNAL', 0);
}

// ----- Optional static temporary directory
//             By default temporary files are generated in the script current
//             path.
//             If defined :
//             - MUST BE terminated by a '/'.
//             - MUST be a valid, already created directory
//             Samples :
// define('PCLZIP_TEMPORARY_DIR', '/temp/');
// define('PCLZIP_TEMPORARY_DIR', 'C:/Temp/');
if (!defined('PCLZIP_TEMPORARY_DIR')) {
    define('PCLZIP_TEMPORARY_DIR', '');
}

// ----- Optional threshold ratio for use of temporary files
//             Pclzip sense the size of the file to add/extract and decide to
//             use or not temporary file. The algorythm is looking for
//             memory_limit of PHP and apply a ratio.
//             threshold = memory_limit * ratio.
//             Recommended values are under 0.5. Default 0.47.
//             Samples :
// define('PCLZIP_TEMPORARY_FILE_RATIO', 0.5);
if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) {
    define('PCLZIP_TEMPORARY_FILE_RATIO', 0.47);
}

// --------------------------------------------------------------------------------
// ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
// --------------------------------------------------------------------------------

// ----- Global variables
$g_pclzip_version = "2.8.2";

// ----- Error codes
//     -1 : Unable to open file in binary write mode
//     -2 : Unable to open file in binary read mode
//     -3 : Invalid parameters
//     -4 : File does not exist
//     -5 : Filename is too long (max. 255)
//     -6 : Not a valid zip file
//     -7 : Invalid extracted file size
//     -8 : Unable to create directory
//     -9 : Invalid archive extension
//    -10 : Invalid archive format
//    -11 : Unable to delete file (unlink)
//    -12 : Unable to rename file (rename)
//    -13 : Invalid header checksum
//    -14 : Invalid archive size
define('PCLZIP_ERR_USER_ABORTED', 2);
define('PCLZIP_ERR_NO_ERROR', 0);
define('PCLZIP_ERR_WRITE_OPEN_FAIL', -1);
define('PCLZIP_ERR_READ_OPEN_FAIL', -2);
define('PCLZIP_ERR_INVALID_PARAMETER', -3);
define('PCLZIP_ERR_MISSING_FILE', -4);
define('PCLZIP_ERR_FILENAME_TOO_LONG', -5);
define('PCLZIP_ERR_INVALID_ZIP', -6);
define('PCLZIP_ERR_BAD_EXTRACTED_FILE', -7);
define('PCLZIP_ERR_DIR_CREATE_FAIL', -8);
define('PCLZIP_ERR_BAD_EXTENSION', -9);
define('PCLZIP_ERR_BAD_FORMAT', -10);
define('PCLZIP_ERR_DELETE_FILE_FAIL', -11);
define('PCLZIP_ERR_RENAME_FILE_FAIL', -12);
define('PCLZIP_ERR_BAD_CHECKSUM', -13);
define('PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14);
define('PCLZIP_ERR_MISSING_OPTION_VALUE', -15);
define('PCLZIP_ERR_INVALID_OPTION_VALUE', -16);
define('PCLZIP_ERR_ALREADY_A_DIRECTORY', -17);
define('PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18);
define('PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19);
define('PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20);
define('PCLZIP_ERR_DIRECTORY_RESTRICTION', -21);

// ----- Options values
define('PCLZIP_OPT_PATH', 77001);
define('PCLZIP_OPT_ADD_PATH', 77002);
define('PCLZIP_OPT_REMOVE_PATH', 77003);
define('PCLZIP_OPT_REMOVE_ALL_PATH', 77004);
define('PCLZIP_OPT_SET_CHMOD', 77005);
define('PCLZIP_OPT_EXTRACT_AS_STRING', 77006);
define('PCLZIP_OPT_NO_COMPRESSION', 77007);
define('PCLZIP_OPT_BY_NAME', 77008);
define('PCLZIP_OPT_BY_INDEX', 77009);
define('PCLZIP_OPT_BY_EREG', 77010);
define('PCLZIP_OPT_BY_PREG', 77011);
define('PCLZIP_OPT_COMMENT', 77012);
define('PCLZIP_OPT_ADD_COMMENT', 77013);
define('PCLZIP_OPT_PREPEND_COMMENT', 77014);
define('PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015);
define('PCLZIP_OPT_REPLACE_NEWER', 77016);
define('PCLZIP_OPT_STOP_ON_ERROR', 77017);
// Having big trouble with crypt. Need to multiply 2 long int
// which is not correctly supported by PHP ...
//define('PCLZIP_OPT_CRYPT', 77018);
define('PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019);
define('PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020);
define('PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020); // alias
define('PCLZIP_OPT_TEMP_FILE_ON', 77021);
define('PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021); // alias
define('PCLZIP_OPT_TEMP_FILE_OFF', 77022);
define('PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022); // alias

// ----- File description attributes
define('PCLZIP_ATT_FILE_NAME', 79001);
define('PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002);
define('PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003);
define('PCLZIP_ATT_FILE_MTIME', 79004);
define('PCLZIP_ATT_FILE_CONTENT', 79005);
define('PCLZIP_ATT_FILE_COMMENT', 79006);

// ----- Call backs values
define('PCLZIP_CB_PRE_EXTRACT', 78001);
define('PCLZIP_CB_POST_EXTRACT', 78002);
define('PCLZIP_CB_PRE_ADD', 78003);
define('PCLZIP_CB_POST_ADD', 78004);
/* For futur use
define('PCLZIP_CB_PRE_LIST', 78005);
define('PCLZIP_CB_POST_LIST', 78006);
define('PCLZIP_CB_PRE_DELETE', 78007);
define('PCLZIP_CB_POST_DELETE', 78008);
*/

// --------------------------------------------------------------------------------
// Class : PclZip
// Description :
//     PclZip is the class that represent a Zip archive.
//     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
// --------------------------------------------------------------------------------
class PclZip
{
    // ----- Filename of the zip file
    public $zipname = '';

    // ----- File descriptor of the zip file
    public $zip_fd = 0;

    // ----- Internal error handling
    public $error_code = 1;
    public $error_string = '';

    // ----- Current status of the magic_quotes_runtime
    // This value store the php configuration for magic_quotes
    // The class can then disable the magic_quotes and reset it after
    public $magic_quotes_status;

    // --------------------------------------------------------------------------------
    // Function : PclZip()
    // Description :
    //     Creates a PclZip object and set the name of the associated Zip archive
    //     filename.
    //     Note that no real action is taken, if the archive does not exist it is not
    //     created. Use create() for that.
    // --------------------------------------------------------------------------------
    public function __construct($p_zipname)
    {

        // ----- Tests the zlib
        if (!function_exists('gzopen')) {
            die('Abort '.basename(__FILE__).' : Missing zlib extensions');
        }

        // ----- Set the attributes
        $this->zipname = $p_zipname;
        $this->zip_fd = 0;
        $this->magic_quotes_status = -1;

        // ----- Return
        return;
    }
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // Function :
    //     create($p_filelist, $p_add_dir="", $p_remove_dir="")
    //     create($p_filelist, $p_option, $p_option_value, ...)
    // Description :
    //     This method supports two different synopsis. The first one is historical.
    //     This method creates a Zip Archive. The Zip file is created in the
    //     filesystem. The files and directories indicated in $p_filelist
    //     are added in the archive. See the parameters description for the
    //     supported format of $p_filelist.
    //     When a directory is in the list, the directory and its content is added
    //     in the archive.
    //     In this synopsis, the function takes an optional variable list of
    //     options. See bellow the supported options.
    // Parameters :
    //     $p_filelist : An array containing file or directory names, or
    //                                 a string containing one filename or one directory name, or
    //                                 a string containing a list of filenames and/or directory
    //                                 names separated by spaces.
    //     $p_add_dir : A path to add before the real path of the archived file,
    //                                in order to have it memorized in the archive.
    //     $p_remove_dir : A path to remove from the real path of the file to archive,
    //                                     in order to have a shorter path memorized in the archive.
    //                                     When $p_add_dir and $p_remove_dir are set, $p_remove_dir
    //                                     is removed first, before $p_add_dir is added.
    // Options :
    //     PCLZIP_OPT_ADD_PATH :
    //     PCLZIP_OPT_REMOVE_PATH :
    //     PCLZIP_OPT_REMOVE_ALL_PATH :
    //     PCLZIP_OPT_COMMENT :
    //     PCLZIP_CB_PRE_ADD :
    //     PCLZIP_CB_POST_ADD :
    // Return Values :
    //     0 on failure,
    //     The list of the added files, with a status of the add action.
    //     (see PclZip::listContent() for list entry format)
    // --------------------------------------------------------------------------------
    public function create($p_filelist)
    {
        $v_result=1;

        // ----- Reset the error handler
        $this->privErrorReset();

        // ----- Set default values
        $v_options = array();
        $v_options[PCLZIP_OPT_NO_COMPRESSION] = false;

        // ----- Look for variable options arguments
        $v_size = func_num_args();

        // ----- Look for arguments
        if ($v_size > 1) {
            // ----- Get the arguments
            $v_arg_list = func_get_args();

            // ----- Remove from the options list the first argument
            array_shift($v_arg_list);
            $v_size--;

            // ----- Look for first arg
            if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
                // ----- Parse the options
                $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (
                    PCLZIP_OPT_REMOVE_PATH => 'optional',
                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
                    PCLZIP_OPT_ADD_PATH => 'optional',
                    PCLZIP_CB_PRE_ADD => 'optional',
                    PCLZIP_CB_POST_ADD => 'optional',
                    PCLZIP_OPT_NO_COMPRESSION => 'optional',
                    PCLZIP_OPT_COMMENT => 'optional',
                    PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
                    PCLZIP_OPT_TEMP_FILE_ON => 'optional',
                    PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
                    //, PCLZIP_OPT_CRYPT => 'optional'
                ));
                if ($v_result != 1) {
                    return 0;
                }
            } else {
                // ----- Look for 2 args
                // Here we need to support the first historic synopsis of the
                // method.
                // ----- Get the first argument
                $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];

                // ----- Look for the optional second argument
                if ($v_size == 2) {
                    $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
                } elseif ($v_size > 2) {
                    PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
                    return 0;
                }
            }
        }

        // ----- Look for default option values
        $this->privOptionDefaultThreshold($v_options);

        // ----- Init
        $v_string_list = array();
        $v_att_list = array();
        $v_filedescr_list = array();
        $p_result_list = array();

        // ----- Look if the $p_filelist is really an array
        if (is_array($p_filelist)) {
            // ----- Look if the first element is also an array
            //             This will mean that this is a file description entry
            if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
                $v_att_list = $p_filelist;
            } else {
                // ----- The list is a list of string names
                $v_string_list = $p_filelist;
            }
        } elseif (is_string($p_filelist)) {
            // ----- Look if the $p_filelist is a string
            // ----- Create a list from the string
            $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
        } else {
            // ----- Invalid variable type for $p_filelist
            PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
            return 0;
        }

        // ----- Reformat the string list
        if (sizeof($v_string_list) != 0) {
            foreach ($v_string_list as $v_string) {
                if ($v_string != '') {
                    $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
                } else {
                }
            }
        }

        // ----- For each file in the list check the attributes
        $v_supported_attributes = array(
            PCLZIP_ATT_FILE_NAME => 'mandatory',
            PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional',
            PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional',
            PCLZIP_ATT_FILE_MTIME => 'optional',
            PCLZIP_ATT_FILE_CONTENT => 'optional',
            PCLZIP_ATT_FILE_COMMENT => 'optional'
        );
        foreach ($v_att_list as $v_entry) {
            $v_result = $this->privFileDescrParseAtt($v_entry, $v_filedescr_list[], $v_options, $v_supported_attributes);
            if ($v_result != 1) {
                return 0;
            }
        }

        // ----- Expand the filelist (expand directories)
        $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
        if ($v_result != 1) {
            return 0;
        }

        // ----- Call the create fct
        $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
        if ($v_result != 1) {
            return 0;
        }

        // ----- Return
        return $p_result_list;
    }
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // Function :
    //     add($p_filelist, $p_add_dir="", $p_remove_dir="")
    //     add($p_filelist, $p_option, $p_option_value, ...)
    // Description :
    //     This method supports two synopsis. The first one is historical.
    //     This methods add the list of files in an existing archive.
    //     If a file with the same name already exists, it is added at the end of the
    //     archive, the first one is still present.
    //     If the archive does not exist, it is created.
    // Parameters :
    //     $p_filelist : An array containing file or directory names, or
    //                                 a string containing one filename or one directory name, or
    //                                 a string containing a list of filenames and/or directory
    //                                 names separated by spaces.
    //     $p_add_dir : A path to add before the real path of the archived file,
    //                                in order to have it memorized in the archive.
    //     $p_remove_dir : A path to remove from the real path of the file to archive,
    //                                     in order to have a shorter path memorized in the archive.
    //                                     When $p_add_dir and $p_remove_dir are set, $p_remove_dir
    //                                     is removed first, before $p_add_dir is added.
    // Options :
    //     PCLZIP_OPT_ADD_PATH :
    //     PCLZIP_OPT_REMOVE_PATH :
    //     PCLZIP_OPT_REMOVE_ALL_PATH :
    //     PCLZIP_OPT_COMMENT :
    //     PCLZIP_OPT_ADD_COMMENT :
    //     PCLZIP_OPT_PREPEND_COMMENT :
    //     PCLZIP_CB_PRE_ADD :
    //     PCLZIP_CB_POST_ADD :
    // Return Values :
    //     0 on failure,
    //     The list of the added files, with a status of the add action.
    //     (see PclZip::listContent() for list entry format)
    // --------------------------------------------------------------------------------
    public function add($p_filelist)
    {
        $v_result=1;

        // ----- Reset the error handler
        $this->privErrorReset();

        // ----- Set default values
        $v_options = array();
        $v_options[PCLZIP_OPT_NO_COMPRESSION] = false;

        // ----- Look for variable options arguments
        $v_size = func_num_args();

        // ----- Look for arguments
        if ($v_size > 1) {
            // ----- Get the arguments
            $v_arg_list = func_get_args();

            // ----- Remove form the options list the first argument
            array_shift($v_arg_list);
            $v_size--;

            // ----- Look for first arg
            if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
                // ----- Parse the options
                $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (
                    PCLZIP_OPT_REMOVE_PATH => 'optional',
                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
                    PCLZIP_OPT_ADD_PATH => 'optional',
                    PCLZIP_CB_PRE_ADD => 'optional',
                    PCLZIP_CB_POST_ADD => 'optional',
                    PCLZIP_OPT_NO_COMPRESSION => 'optional',
                    PCLZIP_OPT_COMMENT => 'optional',
                    PCLZIP_OPT_ADD_COMMENT => 'optional',
                    PCLZIP_OPT_PREPEND_COMMENT => 'optional',
                    PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
                    PCLZIP_OPT_TEMP_FILE_ON => 'optional',
                    PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
                    //, PCLZIP_OPT_CRYPT => 'optional'
                ));
                if ($v_result != 1) {
                    return 0;
                }
            } else {
                // ----- Look for 2 args
                // Here we need to support the first historic synopsis of the
                // method.
                // ----- Get the first argument
                $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];

                // ----- Look for the optional second argument
                if ($v_size == 2) {
                    $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
                } elseif ($v_size > 2) {
                    // ----- Error log
                    PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");

                    // ----- Return
                    return 0;
                }
            }
        }

        // ----- Look for default option values
        $this->privOptionDefaultThreshold($v_options);

        // ----- Init
        $v_string_list = array();
        $v_att_list = array();
        $v_filedescr_list = array();
        $p_result_list = array();

        // ----- Look if the $p_filelist is really an array
        if (is_array($p_filelist)) {
            // ----- Look if the first element is also an array
            //             This will mean that this is a file description entry
            if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
                $v_att_list = $p_filelist;
            } else {
                // ----- The list is a list of string names
                $v_string_list = $p_filelist;
            }
        } elseif (is_string($p_filelist)) {
            // ----- Look if the $p_filelist is a string
            // ----- Create a list from the string
            $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
        } else {
            // ----- Invalid variable type for $p_filelist
            PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
            return 0;
        }

        // ----- Reformat the string list
        if (sizeof($v_string_list) != 0) {
            foreach ($v_string_list as $v_string) {
                $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
            }
        }

        // ----- For each file in the list check the attributes
        $v_supported_attributes = array(
          PCLZIP_ATT_FILE_NAME => 'mandatory',
          PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional',
          PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional',
          PCLZIP_ATT_FILE_MTIME => 'optional',
          PCLZIP_ATT_FILE_CONTENT => 'optional',
          PCLZIP_ATT_FILE_COMMENT => 'optional',
        );
        foreach ($v_att_list as $v_entry) {
            $v_result = $this->privFileDescrParseAtt($v_entry, $v_filedescr_list[], $v_options, $v_supported_attributes);
            if ($v_result != 1) {
                return 0;
            }
        }

        // ----- Expand the filelist (expand directories)
        $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
        if ($v_result != 1) {
            return 0;
        }

        // ----- Call the create fct
        $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
        if ($v_result != 1) {
            return 0;
        }

        // ----- Return
        return $p_result_list;
    }
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // Function : listContent()
    // Description :
    //     This public method, gives the list of the files and directories, with their
    //     properties.
    //     The properties of each entries in the list are (used also in other functions) :
    //         filename : Name of the file. For a create or add action it is the filename
    //                                given by the user. For an extract function it is the filename
    //                                of the extracted file.
    //         stored_filename : Name of the file / directory stored in the archive.
    //         size : Size of the stored file.
    //         compressed_size : Size of the file's data compressed in the archive
    //                                             (without the headers overhead)
    //         mtime : Last known modification date of the file (UNIX timestamp)
    //         comment : Comment associated with the file
    //         folder : true | false
    //         index : index of the file in the archive
    //         status : status of the action (depending of the action) :
    //                            Values are :
    //                                ok : OK !
    //                                filtered : the file / dir is not extracted (filtered by user)
    //                                already_a_directory : the file can not be extracted because a
    //                                                                            directory with the same name already exists
    //                                write_protected : the file can not be extracted because a file
    //                                                                    with the same name already exists and is
    //                                                                    write protected
    //                                newer_exist : the file was not extracted because a newer file exists
    //                                path_creation_fail : the file is not extracted because the folder
    //                                                                         does not exist and can not be created
    //                                write_error : the file was not extracted because there was a
    //                                                            error while writing the file
    //                                read_error : the file was not extracted because there was a error
    //                                                         while reading the file
    //                                invalid_header : the file was not extracted because of an archive
    //                                                                 format error (bad file header)
    //     Note that each time a method can continue operating when there
    //     is an action error on a file, the error is only logged in the file status.
    // Return Values :
    //     0 on an unrecoverable failure,
    //     The list of the files in the archive.
    // --------------------------------------------------------------------------------
    public function listContent()
    {
        $v_result=1;

        // ----- Reset the error handler
        $this->privErrorReset();

        // ----- Check archive
        if (!$this->privCheckFormat()) {
            return(0);
        }

        // ----- Call the extracting fct
        $p_list = array();
        if (($v_result = $this->privList($p_list)) != 1) {
            unset($p_list);
            return(0);
        }

        // ----- Return
        return $p_list;
    }
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // Function :
    //     extract($p_path="./", $p_remove_path="")
    //     extract([$p_option, $p_option_value, ...])
    // Description :
    //     This method supports two synopsis. The first one is historical.
    //     This method extract all the files / directories from the archive to the
    //     folder indicated in $p_path.
    //     If you want to ignore the 'root' part of path of the memorized files
    //     you can indicate this in the optional $p_remove_path parameter.
    //     By default, if a newer file with the same name already exists, the
    //     file is not extracted.
    //
    //     If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
    //     are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
    //     at the end of the path value of PCLZIP_OPT_PATH.
    // Parameters :
    //     $p_path : Path where the files and directories are to be extracted
    //     $p_remove_path : First part ('root' part) of the memorized path
    //                                        (if any similar) to remove while extracting.
    // Options :
    //     PCLZIP_OPT_PATH :
    //     PCLZIP_OPT_ADD_PATH :
    //     PCLZIP_OPT_REMOVE_PATH :
    //     PCLZIP_OPT_REMOVE_ALL_PATH :
    //     PCLZIP_CB_PRE_EXTRACT :
    //     PCLZIP_CB_POST_EXTRACT :
    // Return Values :
    //     0 or a negative value on failure,
    //     The list of the extracted files, with a status of the action.
    //     (see PclZip::listContent() for list entry format)
    // --------------------------------------------------------------------------------
    public function extract()
    {
        $v_result=1;

        // ----- Reset the error handler
        $this->privErrorReset();

        // ----- Check archive
        if (!$this->privCheckFormat()) {
            return(0);
        }

        // ----- Set default values
        $v_options = array();
    //        $v_path = "./";
        $v_path = '';
        $v_remove_path = "";
        $v_remove_all_path = false;

        // ----- Look for variable options arguments
        $v_size = func_num_args();

        // ----- Default values for option
        $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = false;

        // ----- Look for arguments
        if ($v_size > 0) {
            // ----- Get the arguments
            $v_arg_list = func_get_args();

            // ----- Look for first arg
            if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
                // ----- Parse the options
                $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (
                  PCLZIP_OPT_PATH => 'optional',
                  PCLZIP_OPT_REMOVE_PATH => 'optional',
                  PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
                  PCLZIP_OPT_ADD_PATH => 'optional',
                  PCLZIP_CB_PRE_EXTRACT => 'optional',
                  PCLZIP_CB_POST_EXTRACT => 'optional',
                  PCLZIP_OPT_SET_CHMOD => 'optional',
                  PCLZIP_OPT_BY_NAME => 'optional',
                  PCLZIP_OPT_BY_EREG => 'optional',
                  PCLZIP_OPT_BY_PREG => 'optional',
                  PCLZIP_OPT_BY_INDEX => 'optional',
                  PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
                  PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
                  PCLZIP_OPT_REPLACE_NEWER => 'optional',
                  PCLZIP_OPT_STOP_ON_ERROR => 'optional',
                  PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
                  PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
                  PCLZIP_OPT_TEMP_FILE_ON => 'optional',
                  PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
                ));
                if ($v_result != 1) {
                    return 0;
                }

                // ----- Set the arguments
                if (isset($v_options[PCLZIP_OPT_PATH])) {
                    $v_path = $v_options[PCLZIP_OPT_PATH];
                }
                if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
                    $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
                }
                if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
                    $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
                }
                if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
                    // ----- Check for '/' in last path char
                    if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
                        $v_path .= '/';
                    }
                    $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
                }
            } else {
                // ----- Look for 2 args
                // Here we need to support the first historic synopsis of the
                // method.
                // ----- Get the first argument
                $v_path = $v_arg_list[0];

                // ----- Look for the optional second argument
                if ($v_size == 2) {
                    $v_remove_path = $v_arg_list[1];
                } elseif ($v_size > 2) {
                    // ----- Error log
                    PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");

                    // ----- Return
                    return 0;
                }
            }
        }

        // ----- Look for default option values
        $this->privOptionDefaultThreshold($v_options);

        // ----- Trace

        // ----- Call the extracting fct
        $p_list = array();
        $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options);
        if ($v_result < 1) {
            unset($p_list);
            return(0);
        }

        // ----- Return
        return $p_list;
    }
    // --------------------------------------------------------------------------------


    // --------------------------------------------------------------------------------
    // Function :
    //     extractByIndex($p_index, $p_path="./", $p_remove_path="")
    //     extractByIndex($p_index, [$p_option, $p_option_value, ...])
    // Description :
    //     This method supports two synopsis. The first one is historical.
    //     This method is doing a partial extract of the archive.
    //     The extracted files or folders are identified by their index in the
    //     archive (from 0 to n).
    //     Note that if the index identify a folder, only the folder entry is
    //     extracted, not all the files included in the archive.
    // Parameters :
    //     $p_index : A single index (integer) or a string of indexes of files to
    //                            extract. The form of the string is "0,4-6,8-12" with only numbers
    //                            and '-' for range or ',' to separate ranges. No spaces or ';'
    //                            are allowed.
    //     $p_path : Path where the files and directories are to be extracted
    //     $p_remove_path : First part ('root' part) of the memorized path
    //                                        (if any similar) to remove while extracting.
    // Options :
    //     PCLZIP_OPT_PATH :
    //     PCLZIP_OPT_ADD_PATH :
    //     PCLZIP_OPT_REMOVE_PATH :
    //     PCLZIP_OPT_REMOVE_ALL_PATH :
    //     PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
    //         not as files.
    //         The resulting content is in a new field 'content' in the file
    //         structure.
    //         This option must be used alone (any other options are ignored).
    //     PCLZIP_CB_PRE_EXTRACT :
    //     PCLZIP_CB_POST_EXTRACT :
    // Return Values :
    //     0 on failure,
    //     The list of the extracted files, with a status of the action.
    //     (see PclZip::listContent() for list entry format)
    // --------------------------------------------------------------------------------
    //function extractByIndex($p_index, options...)
    public function extractByIndex($p_index)
    {
        $v_result=1;

        // ----- Reset the error handler
        $this->privErrorReset();

        // ----- Check archive
        if (!$this->privCheckFormat()) {
            return(0);
        }

        // ----- Set default values
        $v_options = array();
    //        $v_path = "./";
        $v_path = '';
        $v_remove_path = "";
        $v_remove_all_path = false;

        // ----- Look for variable options arguments
        $v_size = func_num_args();

        // ----- Default values for option
        $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = false;

        // ----- Look for arguments
        if ($v_size > 1) {
            // ----- Get the arguments
            $v_arg_list = func_get_args();

            // ----- Remove form the options list the first argument
            array_shift($v_arg_list);
            $v_size--;

            // ----- Look for first arg
            if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
                // ----- Parse the options
                $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array(
                    PCLZIP_OPT_PATH => 'optional',
                    PCLZIP_OPT_REMOVE_PATH => 'optional',
                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
                    PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
                    PCLZIP_OPT_ADD_PATH => 'optional',
                    PCLZIP_CB_PRE_EXTRACT => 'optional',
                    PCLZIP_CB_POST_EXTRACT => 'optional',
                    PCLZIP_OPT_SET_CHMOD => 'optional',
                    PCLZIP_OPT_REPLACE_NEWER => 'optional',
                    PCLZIP_OPT_STOP_ON_ERROR => 'optional',
                    PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
                    PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
                    PCLZIP_OPT_TEMP_FILE_ON => 'optional',
                    PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
                ));
                if ($v_result != 1) {
                    return 0;
                }

                // ----- Set the arguments
                if (isset($v_options[PCLZIP_OPT_PATH])) {
                    $v_path = $v_options[PCLZIP_OPT_PATH];
                }
                if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
                    $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
                }
                if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
                    $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
                }
                if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
                    // ----- Check for '/' in last path char
                    if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
                        $v_path .= '/';
                    }
                    $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
                }
                if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
                    $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = false;
                } else {
                }
            } else {
                // ----- Look for 2 args
                // Here we need to support the first historic synopsis of the
                // method.

                // ----- Get the first argument
                $v_path = $v_arg_list[0];

                // ----- Look for the optional second argument
                if ($v_size == 2) {
                    $v_remove_path = $v_arg_list[1];
                } elseif ($v_size > 2) {
                    // ----- Error log
                    PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");

                    // ----- Return
                    return 0;
                }
            }
        }

        // ----- Trace

        // ----- Trick
        // Here I want to reuse extractByRule(), so I need to parse the $p_index
        // with privParseOptions()
        $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
        $v_options_trick = array();
        $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, array (PCLZIP_OPT_BY_INDEX => 'optional'));
        if ($v_result != 1) {
            return 0;
        }
        $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];

        // ----- Look for default option values
        $this->privOptionDefaultThreshold($v_options);

        // ----- Call the extracting fct
        if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
            return(0);
        }

        // ----- Return
        return $p_list;
    }
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // Function :
    //     delete([$p_option, $p_option_value, ...])
    // Description :
    //     This method removes files from the archive.
    //     If no parameters are given, then all the archive is emptied.
    // Parameters :
    //     None or optional arguments.
    // Options :
    //     PCLZIP_OPT_BY_INDEX :
    //     PCLZIP_OPT_BY_NAME :
    //     PCLZIP_OPT_BY_EREG :
    //     PCLZIP_OPT_BY_PREG :
    // Return Values :
    //     0 on failure,
    //     The list of the files which are still present in the archive.
    //     (see PclZip::listContent() for list entry format)
    // --------------------------------------------------------------------------------
    public function delete()
    {
        $v_result=1;

        // ----- Reset the error handler
        $this->privErrorReset();

        // ----- Check archive
        if (!$this->privCheckFormat()) {
            return(0);
        }

        // ----- Set default values
        $v_options = array();

        // ----- Look for variable options arguments
        $v_size = func_num_args();

        // ----- Look for arguments
        if ($v_size > 0) {
            // ----- Get the arguments
            $v_arg_list = func_get_args();

            // ----- Parse the options
            $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (
                PCLZIP_OPT_BY_NAME => 'optional',
                PCLZIP_OPT_BY_EREG => 'optional',
                PCLZIP_OPT_BY_PREG => 'optional',
                PCLZIP_OPT_BY_INDEX => 'optional'
            ));
            if ($v_result != 1) {
                    return 0;
            }
        }

        // ----- Magic quotes trick
        $this->privDisableMagicQuotes();

        // ----- Call the delete fct
        $v_list = array();
        if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
            $this->privSwapBackMagicQuotes();
            unset($v_list);
            return(0);
        }

        // ----- Magic quotes trick
        $this->privSwapBackMagicQuotes();

        // ----- Return
        return $v_list;
    }
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // Function : deleteByIndex()
    // Description :
    //     ***** Deprecated *****
    //     delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
    // --------------------------------------------------...
完整源码文件,请先购买后再查看
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2023. 京ICP备09089570号 | 京公网安备11010702000869号