PageRenderTime 479ms CodeModel.GetById 182ms app.highlight 66ms RepoModel.GetById 114ms app.codeStats 3ms

/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/pclzip.lib.php

https://bitbucket.org/speedealing/speedealing
PHP | 5693 lines | 2952 code | 915 blank | 1826 comment | 956 complexity | be4ad6fa5c6f10b2267c2f5c37a96995 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2// --------------------------------------------------------------------------------
   3// PhpConcept Library - Zip Module 2.8.2
   4// --------------------------------------------------------------------------------
   5// License GNU/LGPL - Vincent Blavet - August 2009
   6// http://www.phpconcept.net
   7// --------------------------------------------------------------------------------
   8//
   9// Presentation :
  10//   PclZip is a PHP library that manage ZIP archives.
  11//   So far tests show that archives generated by PclZip are readable by
  12//   WinZip application and other tools.
  13//
  14// Description :
  15//   See readme.txt and http://www.phpconcept.net
  16//
  17// Warning :
  18//   This library and the associated files are non commercial, non professional
  19//   work.
  20//   It should not have unexpected results. However if any damage is caused by
  21//   this software the author can not be responsible.
  22//   The use of this software is at the risk of the user.
  23//
  24// --------------------------------------------------------------------------------
  25// --------------------------------------------------------------------------------
  26
  27  // ----- Constants
  28  if (!defined('PCLZIP_READ_BLOCK_SIZE')) {
  29    define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
  30  }
  31  
  32  // ----- File list separator
  33  // In version 1.x of PclZip, the separator for file list is a space
  34  // (which is not a very smart choice, specifically for windows paths !).
  35  // A better separator should be a comma (,). This constant gives you the
  36  // abilty to change that.
  37  // However notice that changing this value, may have impact on existing
  38  // scripts, using space separated filenames.
  39  // Recommanded values for compatibility with older versions :
  40  //define( 'PCLZIP_SEPARATOR', ' ' );
  41  // Recommanded values for smart separation of filenames.
  42  if (!defined('PCLZIP_SEPARATOR')) {
  43    define( 'PCLZIP_SEPARATOR', ',' );
  44  }
  45
  46  // ----- Error configuration
  47  // 0 : PclZip Class integrated error handling
  48  // 1 : PclError external library error handling. By enabling this
  49  //     you must ensure that you have included PclError library.
  50  // [2,...] : reserved for futur use
  51  if (!defined('PCLZIP_ERROR_EXTERNAL')) {
  52    define( 'PCLZIP_ERROR_EXTERNAL', 0 );
  53  }
  54
  55  // ----- Optional static temporary directory
  56  //       By default temporary files are generated in the script current
  57  //       path.
  58  //       If defined :
  59  //       - MUST BE terminated by a '/'.
  60  //       - MUST be a valid, already created directory
  61  //       Samples :
  62  // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' );
  63  // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' );
  64  if (!defined('PCLZIP_TEMPORARY_DIR')) {
  65    define( 'PCLZIP_TEMPORARY_DIR', '' );
  66  }
  67
  68  // ----- Optional threshold ratio for use of temporary files
  69  //       Pclzip sense the size of the file to add/extract and decide to
  70  //       use or not temporary file. The algorythm is looking for 
  71  //       memory_limit of PHP and apply a ratio.
  72  //       threshold = memory_limit * ratio.
  73  //       Recommended values are under 0.5. Default 0.47.
  74  //       Samples :
  75  // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 );
  76  if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) {
  77    define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 );
  78  }
  79
  80// --------------------------------------------------------------------------------
  81// ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
  82// --------------------------------------------------------------------------------
  83
  84  // ----- Global variables
  85  $g_pclzip_version = "2.8.2";
  86
  87  // ----- Error codes
  88  //   -1 : Unable to open file in binary write mode
  89  //   -2 : Unable to open file in binary read mode
  90  //   -3 : Invalid parameters
  91  //   -4 : File does not exist
  92  //   -5 : Filename is too long (max. 255)
  93  //   -6 : Not a valid zip file
  94  //   -7 : Invalid extracted file size
  95  //   -8 : Unable to create directory
  96  //   -9 : Invalid archive extension
  97  //  -10 : Invalid archive format
  98  //  -11 : Unable to delete file (unlink)
  99  //  -12 : Unable to rename file (rename)
 100  //  -13 : Invalid header checksum
 101  //  -14 : Invalid archive size
 102  define( 'PCLZIP_ERR_USER_ABORTED', 2 );
 103  define( 'PCLZIP_ERR_NO_ERROR', 0 );
 104  define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
 105  define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
 106  define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
 107  define( 'PCLZIP_ERR_MISSING_FILE', -4 );
 108  define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
 109  define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
 110  define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
 111  define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
 112  define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
 113  define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
 114  define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
 115  define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
 116  define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
 117  define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
 118  define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
 119  define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
 120  define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );
 121  define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );
 122  define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );
 123  define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 );
 124  define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 );
 125
 126  // ----- Options values
 127  define( 'PCLZIP_OPT_PATH', 77001 );
 128  define( 'PCLZIP_OPT_ADD_PATH', 77002 );
 129  define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
 130  define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
 131  define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
 132  define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
 133  define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
 134  define( 'PCLZIP_OPT_BY_NAME', 77008 );
 135  define( 'PCLZIP_OPT_BY_INDEX', 77009 );
 136  define( 'PCLZIP_OPT_BY_EREG', 77010 );
 137  define( 'PCLZIP_OPT_BY_PREG', 77011 );
 138  define( 'PCLZIP_OPT_COMMENT', 77012 );
 139  define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
 140  define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
 141  define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
 142  define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );
 143  define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
 144  // Having big trouble with crypt. Need to multiply 2 long int
 145  // which is not correctly supported by PHP ...
 146  //define( 'PCLZIP_OPT_CRYPT', 77018 );
 147  define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );
 148  define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 );
 149  define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias
 150  define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 );
 151  define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias
 152  define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 );
 153  define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias
 154  
 155  // ----- File description attributes
 156  define( 'PCLZIP_ATT_FILE_NAME', 79001 );
 157  define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 );
 158  define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 );
 159  define( 'PCLZIP_ATT_FILE_MTIME', 79004 );
 160  define( 'PCLZIP_ATT_FILE_CONTENT', 79005 );
 161  define( 'PCLZIP_ATT_FILE_COMMENT', 79006 );
 162
 163  // ----- Call backs values
 164  define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
 165  define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
 166  define( 'PCLZIP_CB_PRE_ADD', 78003 );
 167  define( 'PCLZIP_CB_POST_ADD', 78004 );
 168  /* For futur use
 169  define( 'PCLZIP_CB_PRE_LIST', 78005 );
 170  define( 'PCLZIP_CB_POST_LIST', 78006 );
 171  define( 'PCLZIP_CB_PRE_DELETE', 78007 );
 172  define( 'PCLZIP_CB_POST_DELETE', 78008 );
 173  */
 174
 175  // --------------------------------------------------------------------------------
 176  // Class : PclZip
 177  // Description :
 178  //   PclZip is the class that represent a Zip archive.
 179  //   The public methods allow the manipulation of the archive.
 180  // Attributes :
 181  //   Attributes must not be accessed directly.
 182  // Methods :
 183  //   PclZip() : Object creator
 184  //   create() : Creates the Zip archive
 185  //   listContent() : List the content of the Zip archive
 186  //   extract() : Extract the content of the archive
 187  //   properties() : List the properties of the archive
 188  // --------------------------------------------------------------------------------
 189  class PclZip
 190  {
 191    // ----- Filename of the zip file
 192    var $zipname = '';
 193
 194    // ----- File descriptor of the zip file
 195    var $zip_fd = 0;
 196
 197    // ----- Internal error handling
 198    var $error_code = 1;
 199    var $error_string = '';
 200    
 201    // ----- Current status of the magic_quotes_runtime
 202    // This value store the php configuration for magic_quotes
 203    // The class can then disable the magic_quotes and reset it after
 204    var $magic_quotes_status;
 205
 206  // --------------------------------------------------------------------------------
 207  // Function : PclZip()
 208  // Description :
 209  //   Creates a PclZip object and set the name of the associated Zip archive
 210  //   filename.
 211  //   Note that no real action is taken, if the archive does not exist it is not
 212  //   created. Use create() for that.
 213  // --------------------------------------------------------------------------------
 214  function PclZip($p_zipname)
 215  {
 216
 217    // ----- Tests the zlib
 218    if (!function_exists('gzopen'))
 219    {
 220      die('Abort '.basename(__FILE__).' : Missing zlib extensions');
 221    }
 222
 223    // ----- Set the attributes
 224    $this->zipname = $p_zipname;
 225    $this->zip_fd = 0;
 226    $this->magic_quotes_status = -1;
 227
 228    // ----- Return
 229    return;
 230  }
 231  // --------------------------------------------------------------------------------
 232
 233  // --------------------------------------------------------------------------------
 234  // Function :
 235  //   create($p_filelist, $p_add_dir="", $p_remove_dir="")
 236  //   create($p_filelist, $p_option, $p_option_value, ...)
 237  // Description :
 238  //   This method supports two different synopsis. The first one is historical.
 239  //   This method creates a Zip Archive. The Zip file is created in the
 240  //   filesystem. The files and directories indicated in $p_filelist
 241  //   are added in the archive. See the parameters description for the
 242  //   supported format of $p_filelist.
 243  //   When a directory is in the list, the directory and its content is added
 244  //   in the archive.
 245  //   In this synopsis, the function takes an optional variable list of
 246  //   options. See bellow the supported options.
 247  // Parameters :
 248  //   $p_filelist : An array containing file or directory names, or
 249  //                 a string containing one filename or one directory name, or
 250  //                 a string containing a list of filenames and/or directory
 251  //                 names separated by spaces.
 252  //   $p_add_dir : A path to add before the real path of the archived file,
 253  //                in order to have it memorized in the archive.
 254  //   $p_remove_dir : A path to remove from the real path of the file to archive,
 255  //                   in order to have a shorter path memorized in the archive.
 256  //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
 257  //                   is removed first, before $p_add_dir is added.
 258  // Options :
 259  //   PCLZIP_OPT_ADD_PATH :
 260  //   PCLZIP_OPT_REMOVE_PATH :
 261  //   PCLZIP_OPT_REMOVE_ALL_PATH :
 262  //   PCLZIP_OPT_COMMENT :
 263  //   PCLZIP_CB_PRE_ADD :
 264  //   PCLZIP_CB_POST_ADD :
 265  // Return Values :
 266  //   0 on failure,
 267  //   The list of the added files, with a status of the add action.
 268  //   (see PclZip::listContent() for list entry format)
 269  // --------------------------------------------------------------------------------
 270  function create($p_filelist)
 271  {
 272    $v_result=1;
 273
 274    // ----- Reset the error handler
 275    $this->privErrorReset();
 276
 277    // ----- Set default values
 278    $v_options = array();
 279    $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
 280
 281    // ----- Look for variable options arguments
 282    $v_size = func_num_args();
 283
 284    // ----- Look for arguments
 285    if ($v_size > 1) {
 286      // ----- Get the arguments
 287      $v_arg_list = func_get_args();
 288
 289      // ----- Remove from the options list the first argument
 290      array_shift($v_arg_list);
 291      $v_size--;
 292
 293      // ----- Look for first arg
 294      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 295
 296        // ----- Parse the options
 297        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 298                                            array (PCLZIP_OPT_REMOVE_PATH => 'optional',
 299                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 300                                                   PCLZIP_OPT_ADD_PATH => 'optional',
 301                                                   PCLZIP_CB_PRE_ADD => 'optional',
 302                                                   PCLZIP_CB_POST_ADD => 'optional',
 303                                                   PCLZIP_OPT_NO_COMPRESSION => 'optional',
 304                                                   PCLZIP_OPT_COMMENT => 'optional',
 305                                                   PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
 306                                                   PCLZIP_OPT_TEMP_FILE_ON => 'optional',
 307                                                   PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
 308                                                   //, PCLZIP_OPT_CRYPT => 'optional'
 309                                             ));
 310        if ($v_result != 1) {
 311          return 0;
 312        }
 313      }
 314
 315      // ----- Look for 2 args
 316      // Here we need to support the first historic synopsis of the
 317      // method.
 318      else {
 319
 320        // ----- Get the first argument
 321        $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
 322
 323        // ----- Look for the optional second argument
 324        if ($v_size == 2) {
 325          $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
 326        }
 327        else if ($v_size > 2) {
 328          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
 329		                       "Invalid number / type of arguments");
 330          return 0;
 331        }
 332      }
 333    }
 334    
 335    // ----- Look for default option values
 336    $this->privOptionDefaultThreshold($v_options);
 337
 338    // ----- Init
 339    $v_string_list = array();
 340    $v_att_list = array();
 341    $v_filedescr_list = array();
 342    $p_result_list = array();
 343    
 344    // ----- Look if the $p_filelist is really an array
 345    if (is_array($p_filelist)) {
 346    
 347      // ----- Look if the first element is also an array
 348      //       This will mean that this is a file description entry
 349      if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
 350        $v_att_list = $p_filelist;
 351      }
 352      
 353      // ----- The list is a list of string names
 354      else {
 355        $v_string_list = $p_filelist;
 356      }
 357    }
 358
 359    // ----- Look if the $p_filelist is a string
 360    else if (is_string($p_filelist)) {
 361      // ----- Create a list from the string
 362      $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
 363    }
 364
 365    // ----- Invalid variable type for $p_filelist
 366    else {
 367      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
 368      return 0;
 369    }
 370    
 371    // ----- Reformat the string list
 372    if (sizeof($v_string_list) != 0) {
 373      foreach ($v_string_list as $v_string) {
 374        if ($v_string != '') {
 375          $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
 376        }
 377        else {
 378        }
 379      }
 380    }
 381    
 382    // ----- For each file in the list check the attributes
 383    $v_supported_attributes
 384    = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
 385             ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
 386             ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
 387             ,PCLZIP_ATT_FILE_MTIME => 'optional'
 388             ,PCLZIP_ATT_FILE_CONTENT => 'optional'
 389             ,PCLZIP_ATT_FILE_COMMENT => 'optional'
 390						);
 391    foreach ($v_att_list as $v_entry) {
 392      $v_result = $this->privFileDescrParseAtt($v_entry,
 393                                               $v_filedescr_list[],
 394                                               $v_options,
 395                                               $v_supported_attributes);
 396      if ($v_result != 1) {
 397        return 0;
 398      }
 399    }
 400
 401    // ----- Expand the filelist (expand directories)
 402    $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
 403    if ($v_result != 1) {
 404      return 0;
 405    }
 406
 407    // ----- Call the create fct
 408    $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
 409    if ($v_result != 1) {
 410      return 0;
 411    }
 412
 413    // ----- Return
 414    return $p_result_list;
 415  }
 416  // --------------------------------------------------------------------------------
 417
 418  // --------------------------------------------------------------------------------
 419  // Function :
 420  //   add($p_filelist, $p_add_dir="", $p_remove_dir="")
 421  //   add($p_filelist, $p_option, $p_option_value, ...)
 422  // Description :
 423  //   This method supports two synopsis. The first one is historical.
 424  //   This methods add the list of files in an existing archive.
 425  //   If a file with the same name already exists, it is added at the end of the
 426  //   archive, the first one is still present.
 427  //   If the archive does not exist, it is created.
 428  // Parameters :
 429  //   $p_filelist : An array containing file or directory names, or
 430  //                 a string containing one filename or one directory name, or
 431  //                 a string containing a list of filenames and/or directory
 432  //                 names separated by spaces.
 433  //   $p_add_dir : A path to add before the real path of the archived file,
 434  //                in order to have it memorized in the archive.
 435  //   $p_remove_dir : A path to remove from the real path of the file to archive,
 436  //                   in order to have a shorter path memorized in the archive.
 437  //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
 438  //                   is removed first, before $p_add_dir is added.
 439  // Options :
 440  //   PCLZIP_OPT_ADD_PATH :
 441  //   PCLZIP_OPT_REMOVE_PATH :
 442  //   PCLZIP_OPT_REMOVE_ALL_PATH :
 443  //   PCLZIP_OPT_COMMENT :
 444  //   PCLZIP_OPT_ADD_COMMENT :
 445  //   PCLZIP_OPT_PREPEND_COMMENT :
 446  //   PCLZIP_CB_PRE_ADD :
 447  //   PCLZIP_CB_POST_ADD :
 448  // Return Values :
 449  //   0 on failure,
 450  //   The list of the added files, with a status of the add action.
 451  //   (see PclZip::listContent() for list entry format)
 452  // --------------------------------------------------------------------------------
 453  function add($p_filelist)
 454  {
 455    $v_result=1;
 456
 457    // ----- Reset the error handler
 458    $this->privErrorReset();
 459
 460    // ----- Set default values
 461    $v_options = array();
 462    $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
 463
 464    // ----- Look for variable options arguments
 465    $v_size = func_num_args();
 466
 467    // ----- Look for arguments
 468    if ($v_size > 1) {
 469      // ----- Get the arguments
 470      $v_arg_list = func_get_args();
 471
 472      // ----- Remove form the options list the first argument
 473      array_shift($v_arg_list);
 474      $v_size--;
 475
 476      // ----- Look for first arg
 477      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 478
 479        // ----- Parse the options
 480        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 481                                            array (PCLZIP_OPT_REMOVE_PATH => 'optional',
 482                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 483                                                   PCLZIP_OPT_ADD_PATH => 'optional',
 484                                                   PCLZIP_CB_PRE_ADD => 'optional',
 485                                                   PCLZIP_CB_POST_ADD => 'optional',
 486                                                   PCLZIP_OPT_NO_COMPRESSION => 'optional',
 487                                                   PCLZIP_OPT_COMMENT => 'optional',
 488                                                   PCLZIP_OPT_ADD_COMMENT => 'optional',
 489                                                   PCLZIP_OPT_PREPEND_COMMENT => 'optional',
 490                                                   PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
 491                                                   PCLZIP_OPT_TEMP_FILE_ON => 'optional',
 492                                                   PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
 493                                                   //, PCLZIP_OPT_CRYPT => 'optional'
 494												   ));
 495        if ($v_result != 1) {
 496          return 0;
 497        }
 498      }
 499
 500      // ----- Look for 2 args
 501      // Here we need to support the first historic synopsis of the
 502      // method.
 503      else {
 504
 505        // ----- Get the first argument
 506        $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
 507
 508        // ----- Look for the optional second argument
 509        if ($v_size == 2) {
 510          $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
 511        }
 512        else if ($v_size > 2) {
 513          // ----- Error log
 514          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
 515
 516          // ----- Return
 517          return 0;
 518        }
 519      }
 520    }
 521
 522    // ----- Look for default option values
 523    $this->privOptionDefaultThreshold($v_options);
 524
 525    // ----- Init
 526    $v_string_list = array();
 527    $v_att_list = array();
 528    $v_filedescr_list = array();
 529    $p_result_list = array();
 530    
 531    // ----- Look if the $p_filelist is really an array
 532    if (is_array($p_filelist)) {
 533    
 534      // ----- Look if the first element is also an array
 535      //       This will mean that this is a file description entry
 536      if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
 537        $v_att_list = $p_filelist;
 538      }
 539      
 540      // ----- The list is a list of string names
 541      else {
 542        $v_string_list = $p_filelist;
 543      }
 544    }
 545
 546    // ----- Look if the $p_filelist is a string
 547    else if (is_string($p_filelist)) {
 548      // ----- Create a list from the string
 549      $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
 550    }
 551
 552    // ----- Invalid variable type for $p_filelist
 553    else {
 554      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
 555      return 0;
 556    }
 557    
 558    // ----- Reformat the string list
 559    if (sizeof($v_string_list) != 0) {
 560      foreach ($v_string_list as $v_string) {
 561        $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
 562      }
 563    }
 564    
 565    // ----- For each file in the list check the attributes
 566    $v_supported_attributes
 567    = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
 568             ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
 569             ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
 570             ,PCLZIP_ATT_FILE_MTIME => 'optional'
 571             ,PCLZIP_ATT_FILE_CONTENT => 'optional'
 572             ,PCLZIP_ATT_FILE_COMMENT => 'optional'
 573						);
 574    foreach ($v_att_list as $v_entry) {
 575      $v_result = $this->privFileDescrParseAtt($v_entry,
 576                                               $v_filedescr_list[],
 577                                               $v_options,
 578                                               $v_supported_attributes);
 579      if ($v_result != 1) {
 580        return 0;
 581      }
 582    }
 583
 584    // ----- Expand the filelist (expand directories)
 585    $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
 586    if ($v_result != 1) {
 587      return 0;
 588    }
 589
 590    // ----- Call the create fct
 591    $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
 592    if ($v_result != 1) {
 593      return 0;
 594    }
 595
 596    // ----- Return
 597    return $p_result_list;
 598  }
 599  // --------------------------------------------------------------------------------
 600
 601  // --------------------------------------------------------------------------------
 602  // Function : listContent()
 603  // Description :
 604  //   This public method, gives the list of the files and directories, with their
 605  //   properties.
 606  //   The properties of each entries in the list are (used also in other functions) :
 607  //     filename : Name of the file. For a create or add action it is the filename
 608  //                given by the user. For an extract function it is the filename
 609  //                of the extracted file.
 610  //     stored_filename : Name of the file / directory stored in the archive.
 611  //     size : Size of the stored file.
 612  //     compressed_size : Size of the file's data compressed in the archive
 613  //                       (without the headers overhead)
 614  //     mtime : Last known modification date of the file (UNIX timestamp)
 615  //     comment : Comment associated with the file
 616  //     folder : true | false
 617  //     index : index of the file in the archive
 618  //     status : status of the action (depending of the action) :
 619  //              Values are :
 620  //                ok : OK !
 621  //                filtered : the file / dir is not extracted (filtered by user)
 622  //                already_a_directory : the file can not be extracted because a
 623  //                                      directory with the same name already exists
 624  //                write_protected : the file can not be extracted because a file
 625  //                                  with the same name already exists and is
 626  //                                  write protected
 627  //                newer_exist : the file was not extracted because a newer file exists
 628  //                path_creation_fail : the file is not extracted because the folder
 629  //                                     does not exist and can not be created
 630  //                write_error : the file was not extracted because there was a
 631  //                              error while writing the file
 632  //                read_error : the file was not extracted because there was a error
 633  //                             while reading the file
 634  //                invalid_header : the file was not extracted because of an archive
 635  //                                 format error (bad file header)
 636  //   Note that each time a method can continue operating when there
 637  //   is an action error on a file, the error is only logged in the file status.
 638  // Return Values :
 639  //   0 on an unrecoverable failure,
 640  //   The list of the files in the archive.
 641  // --------------------------------------------------------------------------------
 642  function listContent()
 643  {
 644    $v_result=1;
 645
 646    // ----- Reset the error handler
 647    $this->privErrorReset();
 648
 649    // ----- Check archive
 650    if (!$this->privCheckFormat()) {
 651      return(0);
 652    }
 653
 654    // ----- Call the extracting fct
 655    $p_list = array();
 656    if (($v_result = $this->privList($p_list)) != 1)
 657    {
 658      unset($p_list);
 659      return(0);
 660    }
 661
 662    // ----- Return
 663    return $p_list;
 664  }
 665  // --------------------------------------------------------------------------------
 666
 667  // --------------------------------------------------------------------------------
 668  // Function :
 669  //   extract($p_path="./", $p_remove_path="")
 670  //   extract([$p_option, $p_option_value, ...])
 671  // Description :
 672  //   This method supports two synopsis. The first one is historical.
 673  //   This method extract all the files / directories from the archive to the
 674  //   folder indicated in $p_path.
 675  //   If you want to ignore the 'root' part of path of the memorized files
 676  //   you can indicate this in the optional $p_remove_path parameter.
 677  //   By default, if a newer file with the same name already exists, the
 678  //   file is not extracted.
 679  //
 680  //   If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
 681  //   are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
 682  //   at the end of the path value of PCLZIP_OPT_PATH.
 683  // Parameters :
 684  //   $p_path : Path where the files and directories are to be extracted
 685  //   $p_remove_path : First part ('root' part) of the memorized path
 686  //                    (if any similar) to remove while extracting.
 687  // Options :
 688  //   PCLZIP_OPT_PATH :
 689  //   PCLZIP_OPT_ADD_PATH :
 690  //   PCLZIP_OPT_REMOVE_PATH :
 691  //   PCLZIP_OPT_REMOVE_ALL_PATH :
 692  //   PCLZIP_CB_PRE_EXTRACT :
 693  //   PCLZIP_CB_POST_EXTRACT :
 694  // Return Values :
 695  //   0 or a negative value on failure,
 696  //   The list of the extracted files, with a status of the action.
 697  //   (see PclZip::listContent() for list entry format)
 698  // --------------------------------------------------------------------------------
 699  function extract()
 700  {
 701    $v_result=1;
 702
 703    // ----- Reset the error handler
 704    $this->privErrorReset();
 705
 706    // ----- Check archive
 707    if (!$this->privCheckFormat()) {
 708      return(0);
 709    }
 710
 711    // ----- Set default values
 712    $v_options = array();
 713//    $v_path = "./";
 714    $v_path = '';
 715    $v_remove_path = "";
 716    $v_remove_all_path = false;
 717
 718    // ----- Look for variable options arguments
 719    $v_size = func_num_args();
 720
 721    // ----- Default values for option
 722    $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
 723
 724    // ----- Look for arguments
 725    if ($v_size > 0) {
 726      // ----- Get the arguments
 727      $v_arg_list = func_get_args();
 728
 729      // ----- Look for first arg
 730      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 731
 732        // ----- Parse the options
 733        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 734                                            array (PCLZIP_OPT_PATH => 'optional',
 735                                                   PCLZIP_OPT_REMOVE_PATH => 'optional',
 736                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 737                                                   PCLZIP_OPT_ADD_PATH => 'optional',
 738                                                   PCLZIP_CB_PRE_EXTRACT => 'optional',
 739                                                   PCLZIP_CB_POST_EXTRACT => 'optional',
 740                                                   PCLZIP_OPT_SET_CHMOD => 'optional',
 741                                                   PCLZIP_OPT_BY_NAME => 'optional',
 742                                                   PCLZIP_OPT_BY_EREG => 'optional',
 743                                                   PCLZIP_OPT_BY_PREG => 'optional',
 744                                                   PCLZIP_OPT_BY_INDEX => 'optional',
 745                                                   PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
 746                                                   PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
 747                                                   PCLZIP_OPT_REPLACE_NEWER => 'optional'
 748                                                   ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
 749                                                   ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
 750                                                   PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
 751                                                   PCLZIP_OPT_TEMP_FILE_ON => 'optional',
 752                                                   PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
 753												    ));
 754        if ($v_result != 1) {
 755          return 0;
 756        }
 757
 758        // ----- Set the arguments
 759        if (isset($v_options[PCLZIP_OPT_PATH])) {
 760          $v_path = $v_options[PCLZIP_OPT_PATH];
 761        }
 762        if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
 763          $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
 764        }
 765        if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
 766          $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
 767        }
 768        if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
 769          // ----- Check for '/' in last path char
 770          if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
 771            $v_path .= '/';
 772          }
 773          $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
 774        }
 775      }
 776
 777      // ----- Look for 2 args
 778      // Here we need to support the first historic synopsis of the
 779      // method.
 780      else {
 781
 782        // ----- Get the first argument
 783        $v_path = $v_arg_list[0];
 784
 785        // ----- Look for the optional second argument
 786        if ($v_size == 2) {
 787          $v_remove_path = $v_arg_list[1];
 788        }
 789        else if ($v_size > 2) {
 790          // ----- Error log
 791          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
 792
 793          // ----- Return
 794          return 0;
 795        }
 796      }
 797    }
 798
 799    // ----- Look for default option values
 800    $this->privOptionDefaultThreshold($v_options);
 801
 802    // ----- Trace
 803
 804    // ----- Call the extracting fct
 805    $p_list = array();
 806    $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
 807	                                     $v_remove_all_path, $v_options);
 808    if ($v_result < 1) {
 809      unset($p_list);
 810      return(0);
 811    }
 812
 813    // ----- Return
 814    return $p_list;
 815  }
 816  // --------------------------------------------------------------------------------
 817
 818
 819  // --------------------------------------------------------------------------------
 820  // Function :
 821  //   extractByIndex($p_index, $p_path="./", $p_remove_path="")
 822  //   extractByIndex($p_index, [$p_option, $p_option_value, ...])
 823  // Description :
 824  //   This method supports two synopsis. The first one is historical.
 825  //   This method is doing a partial extract of the archive.
 826  //   The extracted files or folders are identified by their index in the
 827  //   archive (from 0 to n).
 828  //   Note that if the index identify a folder, only the folder entry is
 829  //   extracted, not all the files included in the archive.
 830  // Parameters :
 831  //   $p_index : A single index (integer) or a string of indexes of files to
 832  //              extract. The form of the string is "0,4-6,8-12" with only numbers
 833  //              and '-' for range or ',' to separate ranges. No spaces or ';'
 834  //              are allowed.
 835  //   $p_path : Path where the files and directories are to be extracted
 836  //   $p_remove_path : First part ('root' part) of the memorized path
 837  //                    (if any similar) to remove while extracting.
 838  // Options :
 839  //   PCLZIP_OPT_PATH :
 840  //   PCLZIP_OPT_ADD_PATH :
 841  //   PCLZIP_OPT_REMOVE_PATH :
 842  //   PCLZIP_OPT_REMOVE_ALL_PATH :
 843  //   PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
 844  //     not as files.
 845  //     The resulting content is in a new field 'content' in the file
 846  //     structure.
 847  //     This option must be used alone (any other options are ignored).
 848  //   PCLZIP_CB_PRE_EXTRACT :
 849  //   PCLZIP_CB_POST_EXTRACT :
 850  // Return Values :
 851  //   0 on failure,
 852  //   The list of the extracted files, with a status of the action.
 853  //   (see PclZip::listContent() for list entry format)
 854  // --------------------------------------------------------------------------------
 855  //function extractByIndex($p_index, options...)
 856  function extractByIndex($p_index)
 857  {
 858    $v_result=1;
 859
 860    // ----- Reset the error handler
 861    $this->privErrorReset();
 862
 863    // ----- Check archive
 864    if (!$this->privCheckFormat()) {
 865      return(0);
 866    }
 867
 868    // ----- Set default values
 869    $v_options = array();
 870//    $v_path = "./";
 871    $v_path = '';
 872    $v_remove_path = "";
 873    $v_remove_all_path = false;
 874
 875    // ----- Look for variable options arguments
 876    $v_size = func_num_args();
 877
 878    // ----- Default values for option
 879    $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
 880
 881    // ----- Look for arguments
 882    if ($v_size > 1) {
 883      // ----- Get the arguments
 884      $v_arg_list = func_get_args();
 885
 886      // ----- Remove form the options list the first argument
 887      array_shift($v_arg_list);
 888      $v_size--;
 889
 890      // ----- Look for first arg
 891      if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 892
 893        // ----- Parse the options
 894        $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 895                                            array (PCLZIP_OPT_PATH => 'optional',
 896                                                   PCLZIP_OPT_REMOVE_PATH => 'optional',
 897                                                   PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 898                                                   PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
 899                                                   PCLZIP_OPT_ADD_PATH => 'optional',
 900                                                   PCLZIP_CB_PRE_EXTRACT => 'optional',
 901                                                   PCLZIP_CB_POST_EXTRACT => 'optional',
 902                                                   PCLZIP_OPT_SET_CHMOD => 'optional',
 903                                                   PCLZIP_OPT_REPLACE_NEWER => 'optional'
 904                                                   ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
 905                                                   ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
 906                                                   PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
 907                                                   PCLZIP_OPT_TEMP_FILE_ON => 'optional',
 908                                                   PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
 909												   ));
 910        if ($v_result != 1) {
 911          return 0;
 912        }
 913
 914        // ----- Set the arguments
 915        if (isset($v_options[PCLZIP_OPT_PATH])) {
 916          $v_path = $v_options[PCLZIP_OPT_PATH];
 917        }
 918        if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
 919          $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
 920        }
 921        if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
 922          $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
 923        }
 924        if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
 925          // ----- Check for '/' in last path char
 926          if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
 927            $v_path .= '/';
 928          }
 929          $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
 930        }
 931        if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
 932          $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
 933        }
 934        else {
 935        }
 936      }
 937
 938      // ----- Look for 2 args
 939      // Here we need to support the first historic synopsis of the
 940      // method.
 941      else {
 942
 943        // ----- Get the first argument
 944        $v_path = $v_arg_list[0];
 945
 946        // ----- Look for the optional second argument
 947        if ($v_size == 2) {
 948          $v_remove_path = $v_arg_list[1];
 949        }
 950        else if ($v_size > 2) {
 951          // ----- Error log
 952          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
 953
 954          // ----- Return
 955          return 0;
 956        }
 957      }
 958    }
 959
 960    // ----- Trace
 961
 962    // ----- Trick
 963    // Here I want to reuse extractByRule(), so I need to parse the $p_index
 964    // with privParseOptions()
 965    $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
 966    $v_options_trick = array();
 967    $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
 968                                        array (PCLZIP_OPT_BY_INDEX => 'optional' ));
 969    if ($v_result != 1) {
 970        return 0;
 971    }
 972    $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
 973
 974    // ----- Look for default option values
 975    $this->privOptionDefaultThreshold($v_options);
 976
 977    // ----- Call the extracting fct
 978    if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
 979        return(0);
 980    }
 981
 982    // ----- Return
 983    return $p_list;
 984  }
 985  // --------------------------------------------------------------------------------
 986
 987  // --------------------------------------------------------------------------------
 988  // Function :
 989  //   delete([$p_option, $p_option_value, ...])
 990  // Description :
 991  //   This method removes files from the archive.
 992  //   If no parameters are given, then all the archive is emptied.
 993  // Parameters :
 994  //   None or optional arguments.
 995  // Options :
 996  //   PCLZIP_OPT_BY_INDEX :
 997  //   PCLZIP_OPT_BY_NAME :
 998  //   PCLZIP_OPT_BY_EREG : 
 999  //   PCLZIP_OPT_BY_PREG :
1000  // Return Values :
1001  //   0 on failure,
1002  //   The list of the files which are still present in the archive.
1003  //   (see PclZip::listContent() for list entry format)
1004  // --------------------------------------------------------------------------------
1005  function delete()
1006  {
1007    $v_result=1;
1008
1009    // ----- Reset the error handler
1010    $this->privErrorReset();
1011
1012    // ----- Check archive
1013    if (!$this->privCheckFormat()) {
1014      return(0);
1015    }
1016
1017    // ----- Set default values
1018    $v_options = array();
1019
1020    // ----- Look for variable options arguments
1021    $v_size = func_num_args();
1022
1023    // ----- Look for arguments
1024    if ($v_size > 0) {
1025      // ----- Get the arguments
1026      $v_arg_list = func_get_args();
1027
1028      // ----- Parse the options
1029      $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
1030                                        array (PCLZIP_OPT_BY_NAME => 'optional',
1031                                               PCLZIP_OPT_BY_EREG => 'optional',
1032                                               PCLZIP_OPT_BY_PREG => 'optional',
1033                                               PCLZIP_OPT_BY_INDEX => 'optional' ));
1034      if ($v_result != 1) {
1035          return 0;
1036      }
1037    }
1038
1039    // ----- Magic quotes trick
1040    $this->privDisableMagicQuotes();
1041
1042    // ----- Call the delete fct
1043    $v_list = array();
1044    if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
1045      $this->privSwapBackMagicQuotes();
1046      unset($v_list);
1047      return(0);
1048    }
1049
1050    // ----- Magic quotes trick
1051    $this->privSwapBackMagicQuotes();
1052
1053    // ----- Return
1054    return $v_list;
1055  }
1056  // --------------------------------------------------------------------------------
1057
1058  // --------------------------------------------------------------------------------
1059  // Function : deleteByIndex()
1060  // Description :
1061  //   ***** Deprecated *****
1062  //   delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
1063  // --------------------------------------------------------------------------------
1064  function deleteByIndex($p_index)
1065  {
1066    
1067    $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
1068
1069    // ----- Return
1070    return $p_list;
1071  }
1072  // --------------------------------------------------------------------------------
1073
1074  // --------------------------------------------------------------------------------
1075  // Function : properties()
1076  // Description :
1077  //   This method gives the properties of the archive.
1078  //   The properties are :
1079  //     nb : Number of files in the archive
1080  //     comment : Comment associated with the archive file
1081  //     status : not_exist, ok
1082  // Parameters :
1083  //   None
1084  // Return Values :
1085  //   0 on failure,
1086  //   An array with the archive properties.
1087  // --------------------------------------------------------------------------------
1088  function properties()
1089  {
1090
1091    // ----- Reset the error handler
1092    $this->privErrorReset();
1093
1094    // ----- Magic quotes trick
1095    $this->privDisableMagicQuotes();
1096
1097    // ----- Check archive
1098    if (!$this->privCheckFormat()) {
1099      $this->privSwapBackMagicQuotes();
1100      return(0);
1101    }
1102
1103    // ----- Default properties
1104    $v_prop = array();
1105    $v_prop['comment'] = '';
1106    $v_prop['nb'] = 0;
1107    $v_prop['status'] = 'not_exist';
1108
1109    // ----- Look if file exists
1110    if (@is_file($this->zipname))
1111    {
1112      // ----- Open the zip file
1113      if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
1114      {
1115        $this->privSwapBackMagicQuotes();
1116        
1117        // ----- Error log
1118        PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
1119
1120        // ----- Return
1121        return 0;
1122      }
1123
1124      // ----- Read the central directory informations
1125      $v_central_dir = array();
1126      if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
1127      {
1128        $this->privSwapBackMagicQuotes();
1129        return 0;
1130      }
1131
1132      // ----- Close the zip file
1133      $this->privCloseFd();
1134
1135      // ----- Set the user attributes
1136      $v_prop['comment'] = $v_central_dir['comment'];
1137      $v_prop['nb'] = $v_central_dir['entries'];
1138      $v_prop['status'] = 'ok';
1139    }
1140
1141    // ----- Magic quotes trick
1142    $this->privSwapBackMagicQuotes();
1143
1144    // ----- Return
1145    return $v_prop;
1146  }
1147  // --------------------------------------------------------------------------------
1148
1149  // --------------------------------------------------------------------------------
1150  // Function : duplicate()
1151  // Description :
1152  //   This method creates an archive by copying the content of an other one. If
1153  //   the archive already exist, it is replaced by the new one without any warning.
1154  // Parameters :
1155  //   $p_archive : The filename of a valid archive, or
1156  //                a valid PclZip object.
1157  // Return Values :
1158  //   1 on success.
1159  //   0 or a negative value on error (error code).
1160  // --------------------------------------------------------------------------------
1161  function duplicate($p_archive)
1162  {
1163    $v_result = 1;
1164
1165    // ----- Reset the error handler
1166    $this->privErrorReset();
1167
1168    // ----- Look if the $p_archive is a PclZip object
1169    if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
1170    {
1171
1172      // ----- Duplicate the archive
1173      $v_result = $this->privDuplicate($p_archive->zipname);
1174    }
1175
1176    // ----- Look if the $p_archive is a string (so a filename)
1177    else if (is_string($p_archive))
1178    {
1179
1180      // ----- Check that $p_archive is a valid zip file
1181      // TBC : Should also check the archive format
1182      if (!is_file($p_archive)) {
1183        // ----- Error log
1184        PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
1185        $v_result = PCLZIP_ERR_MISSING_FILE;
1186      }
1187      else {
1188        // ----- Duplicate the archive
1189        $v_result = $this->privDuplicate($p_archive);
1190      }
1191    }
1192
1193    // ----- Invalid variable
1194    else
1195    {
1196      // ----- Error log
1197      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
1198      $v_result = PCLZIP_ERR_INVALID_PARAMETER;
1199    }
1200
1201    // ----- Return
1202    return $v_result;
1203  }
1204  // --------------------------------------------------------------------------------
1205
1206  // --------------------------------------------------------------------------------
1207  // Function : merge()
1208  // Description :
1209  //   This method merge the $p_archive_to_add archive at the end of the current
1210  //   one ($this).
1211  //   If the archive ($this) does not exist, the merge becomes a duplicate.
1212  //   If the $p_archive_to_add archive does not exist, the merge is a success.
1213  // Parameters :
1214  //   $p_archive_to_add : It can be directly the filename of a valid zip archive,
1215  //                       or a PclZip object archive.
1216  // Return Values :
1217  //   1 on success,
1218  //   0 or negative values on error (see below).
1219  // --------------------------------------------------------------------------------
1220  function merge($p_archive_to_add)
1221  {
1222    $v_result = 1;
1223
1224    // ----- Reset the error handler
1225    $this->privErrorReset();
1226
1227    // ----- Check archive
1228    if (!$this->privCheckFormat()) {
1229      return(0);
1230    }
1231
1232    // ----- Look if the $p_archive_to_add is a PclZip object
1233    if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
1234    {
1235
1236      // ----- Merge the archive
1237      $v_result = $this->privMerge($p_archive_to_add);
1238    }
1239
1240    // ----- Look if the $p_archive_to_add is a string (so a filename)
1241    else if (is_string($p_archive_to_add))
1242    {
1243
1244      // ----- Create a temporary archive
1245      $v_object_archive = new PclZip($p_archive_to_add);
1246
1247      // ----- Merge the archive
1248      $v_result = $this->privMerge($v_object_archive);
1249    }
1250
1251    // ----- Invalid variable
1252    else
1253    {
1254      // ----- Error log
1255      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
1256      $v_result = PCLZIP_ERR_INVALID_PARAMETER;
1257    }
1258
1259    // ----- Return
1260    return $v_result;
1261  }
1262  // --------------------------------------------------------------------------------
1263
1264
1265
1266  // --------------------------------------------------------------------------------
1267  // Function : errorCode()
1268  // Description :
1269  // Parameters :
1270  // --------------------------------------------------------------------------------
1271  function errorCode()
1272  {
1273    if (PCLZIP_ERROR_EXTERNAL == 1) {
1274      return(PclErrorCode());
1275    }
1276    else {
1277      return($this->error_code);
1278    }
1279  }
1280  // --------------------------------------------------------------------------------
1281
1282  // --------------------------------------------------------------------------------
1283  // Function : errorName()
1284  // Description :
1285  // Parameters :
1286  // --------------------------------------------------------------------------------
1287  function errorName($p_with_code=false)
1288  {
1289    $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
1290                      PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
1291                      PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
1292                      PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
1293                      PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
1294                      PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
1295                      PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
1296                      PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
1297                      PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
1298                      PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
1299                      PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
1300                      PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
1301                      PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
1302                      PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
1303                      PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
1304                      PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
1305                      PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
1306                      PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
1307                      PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
1308            

Large files files are truncated, but you can click here to view the full file