Changeset 11025
- Timestamp:
- 04/20/2009 10:25:40 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/includes/class-pclzip.php (modified) (76 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-pclzip.php
r8645 r11025 1 1 <?php 2 /** 3 * PhpConcept Library - Zip Module 2.5 4 * 5 * Presentation : 6 * PclZip is a PHP library that manage ZIP archives. 7 * So far tests show that archives generated by PclZip are readable by 8 * WinZip application and other tools. 9 * 10 * Warning : 11 * This library and the associated files are non commercial, non professional 12 * work. 13 * It should not have unexpected results. However if any damage is caused by 14 * this software the author can not be responsible. 15 * The use of this software is at the risk of the user. 16 * 17 * @package External 18 * @subpackage PclZip 19 * 20 * @license License GNU/LGPL 21 * @copyright March 2006 Vincent Blavet 22 * @author Vincent Blavet 23 * @link http://www.phpconcept.net 24 * @version $Id: pclzip.lib.php,v 1.44 2006/03/08 21:23:59 vblavet Exp $ 25 */ 26 27 /** 28 * The read block size for reading zip files. 29 * 30 * @since 2.5 31 */ 32 define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); 33 34 /** 35 * File list separator 36 * 37 * In version 1.x of PclZip, the separator for file list is a space(which is not 38 * a very smart choice, specifically for windows paths !). A better separator 39 * should be a comma (,). This constant gives you the abilty to change that. 40 * 41 * However notice that changing this value, may have impact on existing scripts, 42 * using space separated filenames. Recommanded values for compatibility with 43 * older versions : 44 * <code>define( 'PCLZIP_SEPARATOR', ' ' );</code> 45 * Recommanded values for smart separation of filenames. 46 */ 47 define( 'PCLZIP_SEPARATOR', ',' ); 48 49 /** 50 * Error configuration 51 * 52 * 0 : PclZip Class integrated error handling 53 * 1 : PclError external library error handling. By enabling this you must 54 * ensure that you have included PclError library. 55 * [2,...] : reserved for future use 56 */ 57 define( 'PCLZIP_ERROR_EXTERNAL', 0 ); 2 // -------------------------------------------------------------------------------- 3 // PhpConcept Library - Zip Module 2.7 4 // -------------------------------------------------------------------------------- 5 // License GNU/LGPL - Vincent Blavet - March 2006 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 // $Id: pclzip.lib.php,v 1.50 2009/03/24 17:13:52 vblavet Exp $ 26 // -------------------------------------------------------------------------------- 27 28 // ----- Constants 29 if (!defined('PCLZIP_READ_BLOCK_SIZE')) { 30 define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); 31 } 32 33 // ----- File list separator 34 // In version 1.x of PclZip, the separator for file list is a space 35 // (which is not a very smart choice, specifically for windows paths !). 36 // A better separator should be a comma (,). This constant gives you the 37 // abilty to change that. 38 // However notice that changing this value, may have impact on existing 39 // scripts, using space separated filenames. 40 // Recommanded values for compatibility with older versions : 41 //define( 'PCLZIP_SEPARATOR', ' ' ); 42 // Recommanded values for smart separation of filenames. 43 if (!defined('PCLZIP_SEPARATOR')) { 44 define( 'PCLZIP_SEPARATOR', ',' ); 45 } 46 47 // ----- Error configuration 48 // 0 : PclZip Class integrated error handling 49 // 1 : PclError external library error handling. By enabling this 50 // you must ensure that you have included PclError library. 51 // [2,...] : reserved for futur use 52 if (!defined('PCLZIP_ERROR_EXTERNAL')) { 53 define( 'PCLZIP_ERROR_EXTERNAL', 0 ); 54 } 58 55 59 56 // ----- Optional static temporary directory 60 // By default temporary files are generated in the script current61 // path.62 // If defined :63 // - MUST BE terminated by a '/'.64 // - MUST be a valid, already created directory65 // Samples :57 // By default temporary files are generated in the script current 58 // path. 59 // If defined : 60 // - MUST BE terminated by a '/'. 61 // - MUST be a valid, already created directory 62 // Samples : 66 63 // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' ); 67 64 // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' ); 68 define( 'PCLZIP_TEMPORARY_DIR', '' ); 65 if (!defined('PCLZIP_TEMPORARY_DIR')) { 66 define( 'PCLZIP_TEMPORARY_DIR', '' ); 67 } 69 68 70 69 // -------------------------------------------------------------------------------- … … 73 72 74 73 // ----- Global variables 75 $g_pclzip_version = "2. 5";74 $g_pclzip_version = "2.7"; 76 75 77 76 // ----- Error codes … … 136 135 //define( 'PCLZIP_OPT_CRYPT', 77018 ); 137 136 define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); 138 137 define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); 138 define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); 139 define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); 140 139 141 // ----- File description attributes 140 142 define( 'PCLZIP_ATT_FILE_NAME', 79001 ); 141 143 define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 ); 142 144 define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 ); 145 define( 'PCLZIP_ATT_FILE_MTIME', 79004 ); 146 define( 'PCLZIP_ATT_FILE_CONTENT', 79005 ); 147 define( 'PCLZIP_ATT_FILE_COMMENT', 79006 ); 143 148 144 149 // ----- Call backs values … … 147 152 define( 'PCLZIP_CB_PRE_ADD', 78003 ); 148 153 define( 'PCLZIP_CB_POST_ADD', 78004 ); 149 /* For futur euse154 /* For futur use 150 155 define( 'PCLZIP_CB_PRE_LIST', 78005 ); 151 156 define( 'PCLZIP_CB_POST_LIST', 78006 ); … … 170 175 class PclZip 171 176 { 172 // ----- Filename of the zip file173 var $zipname = '';174 175 // ----- File descriptor of the zip file176 var $zip_fd = 0;177 178 // ----- Internal error handling179 var $error_code = 1;180 var $error_string = '';181 182 // ----- Current status of the magic_quotes_runtime183 // This value store the php configuration for magic_quotes184 // The class can then disable the magic_quotes and reset it after185 var $magic_quotes_status;177 // ----- Filename of the zip file 178 var $zipname = ''; 179 180 // ----- File descriptor of the zip file 181 var $zip_fd = 0; 182 183 // ----- Internal error handling 184 var $error_code = 1; 185 var $error_string = ''; 186 187 // ----- Current status of the magic_quotes_runtime 188 // This value store the php configuration for magic_quotes 189 // The class can then disable the magic_quotes and reset it after 190 var $magic_quotes_status; 186 191 187 192 // -------------------------------------------------------------------------------- … … 195 200 function PclZip($p_zipname) 196 201 { 197 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname");198 199 // ----- Tests the zlib200 if (!function_exists('gzopen'))201 {202 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing");203 die('Abort '.basename(__FILE__).' : Missing zlib extensions');204 }205 206 // ----- Set the attributes207 $this->zipname = $p_zipname;208 $this->zip_fd = 0;209 $this->magic_quotes_status = -1;210 211 // ----- Return212 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1);213 return;202 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname"); 203 204 // ----- Tests the zlib 205 if (!function_exists('gzopen')) 206 { 207 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing"); 208 die('Abort '.basename(__FILE__).' : Missing zlib extensions'); 209 } 210 211 // ----- Set the attributes 212 $this->zipname = $p_zipname; 213 $this->zip_fd = 0; 214 $this->magic_quotes_status = -1; 215 216 // ----- Return 217 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1); 218 return; 214 219 } 215 220 // -------------------------------------------------------------------------------- … … 231 236 // Parameters : 232 237 // $p_filelist : An array containing file or directory names, or 233 // a string containing one filename or one directory name, or234 // a string containing a list of filenames and/or directory235 // names separated by spaces.238 // a string containing one filename or one directory name, or 239 // a string containing a list of filenames and/or directory 240 // names separated by spaces. 236 241 // $p_add_dir : A path to add before the real path of the archived file, 237 // in order to have it memorized in the archive.242 // in order to have it memorized in the archive. 238 243 // $p_remove_dir : A path to remove from the real path of the file to archive, 239 // in order to have a shorter path memorized in the archive.240 // When $p_add_dir and $p_remove_dir are set, $p_remove_dir241 // is removed first, before $p_add_dir is added.244 // in order to have a shorter path memorized in the archive. 245 // When $p_add_dir and $p_remove_dir are set, $p_remove_dir 246 // is removed first, before $p_add_dir is added. 242 247 // Options : 243 248 // PCLZIP_OPT_ADD_PATH : … … 254 259 function create($p_filelist) 255 260 { 256 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ..."); 257 $v_result=1; 258 259 // ----- Reset the error handler 260 $this->privErrorReset(); 261 262 // ----- Set default values 263 $v_options = array(); 264 $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; 265 266 // ----- Look for variable options arguments 267 $v_size = func_num_args(); 268 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); 269 270 // ----- Look for arguments 271 if ($v_size > 1) { 272 // ----- Get the arguments 273 $v_arg_list = func_get_args(); 274 275 // ----- Remove from the options list the first argument 276 array_shift($v_arg_list); 277 $v_size--; 278 279 // ----- Look for first arg 280 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 281 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected"); 282 283 // ----- Parse the options 284 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 285 array (PCLZIP_OPT_REMOVE_PATH => 'optional', 286 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 287 PCLZIP_OPT_ADD_PATH => 'optional', 288 PCLZIP_CB_PRE_ADD => 'optional', 289 PCLZIP_CB_POST_ADD => 'optional', 290 PCLZIP_OPT_NO_COMPRESSION => 'optional', 291 PCLZIP_OPT_COMMENT => 'optional' 292 //, PCLZIP_OPT_CRYPT => 'optional' 293 )); 294 if ($v_result != 1) { 295 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 296 return 0; 297 } 298 } 299 300 // ----- Look for 2 args 301 // Here we need to support the first historic synopsis of the 302 // method. 303 else { 304 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); 305 306 // ----- Get the first argument 307 $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0]; 308 309 // ----- Look for the optional second argument 310 if ($v_size == 2) { 311 $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; 312 } 313 else if ($v_size > 2) { 314 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 315 "Invalid number / type of arguments"); 316 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 317 return 0; 318 } 319 } 320 } 321 322 // ----- Init 323 $v_string_list = array(); 324 $v_att_list = array(); 325 $v_filedescr_list = array(); 326 $p_result_list = array(); 327 328 // ----- Look if the $p_filelist is really an array 329 if (is_array($p_filelist)) { 330 331 // ----- Look if the first element is also an array 332 // This will mean that this is a file description entry 333 if (isset($p_filelist[0]) && is_array($p_filelist[0])) { 334 $v_att_list = $p_filelist; 335 } 336 337 // ----- The list is a list of string names 338 else { 339 $v_string_list = $p_filelist; 340 } 341 } 342 343 // ----- Look if the $p_filelist is a string 344 else if (is_string($p_filelist)) { 345 // ----- Create a list from the string 346 $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); 347 } 348 349 // ----- Invalid variable type for $p_filelist 350 else { 351 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); 352 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 353 return 0; 354 } 355 356 // ----- Reformat the string list 357 if (sizeof($v_string_list) != 0) { 358 foreach ($v_string_list as $v_string) { 359 if ($v_string != '') { 360 $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; 361 } 362 else { 363 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Ignore an empty filename"); 364 } 365 } 366 } 367 368 // ----- For each file in the list check the attributes 369 $v_supported_attributes 370 = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' 371 ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' 372 ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' 261 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ..."); 262 $v_result=1; 263 264 // ----- Reset the error handler 265 $this->privErrorReset(); 266 267 // ----- Set default values 268 $v_options = array(); 269 $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; 270 271 // ----- Look for variable options arguments 272 $v_size = func_num_args(); 273 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); 274 275 // ----- Look for arguments 276 if ($v_size > 1) { 277 // ----- Get the arguments 278 $v_arg_list = func_get_args(); 279 280 // ----- Remove from the options list the first argument 281 array_shift($v_arg_list); 282 $v_size--; 283 284 // ----- Look for first arg 285 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 286 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected"); 287 288 // ----- Parse the options 289 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 290 array (PCLZIP_OPT_REMOVE_PATH => 'optional', 291 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 292 PCLZIP_OPT_ADD_PATH => 'optional', 293 PCLZIP_CB_PRE_ADD => 'optional', 294 PCLZIP_CB_POST_ADD => 'optional', 295 PCLZIP_OPT_NO_COMPRESSION => 'optional', 296 PCLZIP_OPT_COMMENT => 'optional', 297 PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD => 'optional', 298 PCLZIP_OPT_ADD_TEMP_FILE_ON => 'optional', 299 PCLZIP_OPT_ADD_TEMP_FILE_OFF => 'optional' 300 //, PCLZIP_OPT_CRYPT => 'optional' 301 )); 302 if ($v_result != 1) { 303 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 304 return 0; 305 } 306 } 307 308 // ----- Look for 2 args 309 // Here we need to support the first historic synopsis of the 310 // method. 311 else { 312 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); 313 314 // ----- Get the first argument 315 $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0]; 316 317 // ----- Look for the optional second argument 318 if ($v_size == 2) { 319 $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; 320 } 321 else if ($v_size > 2) { 322 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 323 "Invalid number / type of arguments"); 324 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 325 return 0; 326 } 327 } 328 } 329 330 // ----- Look for default option values 331 if (!isset($v_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) { 332 $this->privOptionDefaultThreshold($v_options); 333 } 334 335 // ----- Init 336 $v_string_list = array(); 337 $v_att_list = array(); 338 $v_filedescr_list = array(); 339 $p_result_list = array(); 340 341 // ----- Look if the $p_filelist is really an array 342 if (is_array($p_filelist)) { 343 344 // ----- Look if the first element is also an array 345 // This will mean that this is a file description entry 346 if (isset($p_filelist[0]) && is_array($p_filelist[0])) { 347 $v_att_list = $p_filelist; 348 } 349 350 // ----- The list is a list of string names 351 else { 352 $v_string_list = $p_filelist; 353 } 354 } 355 356 // ----- Look if the $p_filelist is a string 357 else if (is_string($p_filelist)) { 358 // ----- Create a list from the string 359 $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); 360 } 361 362 // ----- Invalid variable type for $p_filelist 363 else { 364 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); 365 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 366 return 0; 367 } 368 369 // ----- Reformat the string list 370 if (sizeof($v_string_list) != 0) { 371 foreach ($v_string_list as $v_string) { 372 if ($v_string != '') { 373 $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; 374 } 375 else { 376 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Ignore an empty filename"); 377 } 378 } 379 } 380 381 // ----- For each file in the list check the attributes 382 $v_supported_attributes 383 = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' 384 ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' 385 ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' 386 ,PCLZIP_ATT_FILE_MTIME => 'optional' 387 ,PCLZIP_ATT_FILE_CONTENT => 'optional' 388 ,PCLZIP_ATT_FILE_COMMENT => 'optional' 373 389 ); 374 foreach ($v_att_list as $v_entry) {375 $v_result = $this->privFileDescrParseAtt($v_entry,376 $v_filedescr_list[],377 $v_options,378 $v_supported_attributes);379 if ($v_result != 1) {380 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);381 return 0;382 }383 }384 385 // ----- Expand the filelist (expand directories)386 $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);387 if ($v_result != 1) {388 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);389 return 0;390 }391 392 // ----- Call the create fct393 $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);394 if ($v_result != 1) {395 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);396 return 0;397 }398 399 // ----- Return400 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);401 return $p_result_list;390 foreach ($v_att_list as $v_entry) { 391 $v_result = $this->privFileDescrParseAtt($v_entry, 392 $v_filedescr_list[], 393 $v_options, 394 $v_supported_attributes); 395 if ($v_result != 1) { 396 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 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 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 405 return 0; 406 } 407 408 // ----- Call the create fct 409 $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options); 410 if ($v_result != 1) { 411 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 412 return 0; 413 } 414 415 // ----- Return 416 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list); 417 return $p_result_list; 402 418 } 403 419 // -------------------------------------------------------------------------------- … … 415 431 // Parameters : 416 432 // $p_filelist : An array containing file or directory names, or 417 // a string containing one filename or one directory name, or418 // a string containing a list of filenames and/or directory419 // names separated by spaces.433 // a string containing one filename or one directory name, or 434 // a string containing a list of filenames and/or directory 435 // names separated by spaces. 420 436 // $p_add_dir : A path to add before the real path of the archived file, 421 // in order to have it memorized in the archive.437 // in order to have it memorized in the archive. 422 438 // $p_remove_dir : A path to remove from the real path of the file to archive, 423 // in order to have a shorter path memorized in the archive.424 // When $p_add_dir and $p_remove_dir are set, $p_remove_dir425 // is removed first, before $p_add_dir is added.439 // in order to have a shorter path memorized in the archive. 440 // When $p_add_dir and $p_remove_dir are set, $p_remove_dir 441 // is removed first, before $p_add_dir is added. 426 442 // Options : 427 443 // PCLZIP_OPT_ADD_PATH : … … 440 456 function add($p_filelist) 441 457 { 442 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ..."); 443 $v_result=1; 444 445 // ----- Reset the error handler 446 $this->privErrorReset(); 447 448 // ----- Set default values 449 $v_options = array(); 450 $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; 451 452 // ----- Look for variable options arguments 453 $v_size = func_num_args(); 454 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); 455 456 // ----- Look for arguments 457 if ($v_size > 1) { 458 // ----- Get the arguments 459 $v_arg_list = func_get_args(); 460 461 // ----- Remove form the options list the first argument 462 array_shift($v_arg_list); 463 $v_size--; 464 465 // ----- Look for first arg 466 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 467 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected"); 468 469 // ----- Parse the options 470 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 471 array (PCLZIP_OPT_REMOVE_PATH => 'optional', 472 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 473 PCLZIP_OPT_ADD_PATH => 'optional', 474 PCLZIP_CB_PRE_ADD => 'optional', 475 PCLZIP_CB_POST_ADD => 'optional', 476 PCLZIP_OPT_NO_COMPRESSION => 'optional', 477 PCLZIP_OPT_COMMENT => 'optional', 478 PCLZIP_OPT_ADD_COMMENT => 'optional', 479 PCLZIP_OPT_PREPEND_COMMENT => 'optional' 480 //, PCLZIP_OPT_CRYPT => 'optional' 458 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ..."); 459 $v_result=1; 460 461 // ----- Reset the error handler 462 $this->privErrorReset(); 463 464 // ----- Set default values 465 $v_options = array(); 466 $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; 467 468 // ----- Look for variable options arguments 469 $v_size = func_num_args(); 470 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); 471 472 // ----- Look for arguments 473 if ($v_size > 1) { 474 // ----- Get the arguments 475 $v_arg_list = func_get_args(); 476 477 // ----- Remove form the options list the first argument 478 array_shift($v_arg_list); 479 $v_size--; 480 481 // ----- Look for first arg 482 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 483 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected"); 484 485 // ----- Parse the options 486 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 487 array (PCLZIP_OPT_REMOVE_PATH => 'optional', 488 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 489 PCLZIP_OPT_ADD_PATH => 'optional', 490 PCLZIP_CB_PRE_ADD => 'optional', 491 PCLZIP_CB_POST_ADD => 'optional', 492 PCLZIP_OPT_NO_COMPRESSION => 'optional', 493 PCLZIP_OPT_COMMENT => 'optional', 494 PCLZIP_OPT_ADD_COMMENT => 'optional', 495 PCLZIP_OPT_PREPEND_COMMENT => 'optional', 496 PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD => 'optional', 497 PCLZIP_OPT_ADD_TEMP_FILE_ON => 'optional', 498 PCLZIP_OPT_ADD_TEMP_FILE_OFF => 'optional' 499 //, PCLZIP_OPT_CRYPT => 'optional' 481 500 )); 482 if ($v_result != 1) { 483 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 484 return 0; 485 } 486 } 487 488 // ----- Look for 2 args 489 // Here we need to support the first historic synopsis of the 490 // method. 491 else { 492 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); 493 494 // ----- Get the first argument 495 $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0]; 496 497 // ----- Look for the optional second argument 498 if ($v_size == 2) { 499 $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; 500 } 501 else if ($v_size > 2) { 502 // ----- Error log 503 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); 504 505 // ----- Return 506 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 507 return 0; 508 } 509 } 510 } 511 512 // ----- Init 513 $v_string_list = array(); 514 $v_att_list = array(); 515 $v_filedescr_list = array(); 516 $p_result_list = array(); 517 518 // ----- Look if the $p_filelist is really an array 519 if (is_array($p_filelist)) { 520 521 // ----- Look if the first element is also an array 522 // This will mean that this is a file description entry 523 if (isset($p_filelist[0]) && is_array($p_filelist[0])) { 524 $v_att_list = $p_filelist; 525 } 526 527 // ----- The list is a list of string names 528 else { 529 $v_string_list = $p_filelist; 530 } 531 } 532 533 // ----- Look if the $p_filelist is a string 534 else if (is_string($p_filelist)) { 535 // ----- Create a list from the string 536 $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); 537 } 538 539 // ----- Invalid variable type for $p_filelist 540 else { 541 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); 542 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 543 return 0; 544 } 545 546 // ----- Reformat the string list 547 if (sizeof($v_string_list) != 0) { 548 foreach ($v_string_list as $v_string) { 549 $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; 550 } 551 } 552 553 // ----- For each file in the list check the attributes 554 $v_supported_attributes 555 = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' 556 ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' 557 ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' 501 if ($v_result != 1) { 502 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 503 return 0; 504 } 505 } 506 507 // ----- Look for 2 args 508 // Here we need to support the first historic synopsis of the 509 // method. 510 else { 511 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); 512 513 // ----- Get the first argument 514 $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0]; 515 516 // ----- Look for the optional second argument 517 if ($v_size == 2) { 518 $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; 519 } 520 else if ($v_size > 2) { 521 // ----- Error log 522 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); 523 524 // ----- Return 525 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 526 return 0; 527 } 528 } 529 } 530 531 // ----- Look for default option values 532 if (!isset($v_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) { 533 $this->privOptionDefaultThreshold($v_options); 534 } 535 536 // ----- Init 537 $v_string_list = array(); 538 $v_att_list = array(); 539 $v_filedescr_list = array(); 540 $p_result_list = array(); 541 542 // ----- Look if the $p_filelist is really an array 543 if (is_array($p_filelist)) { 544 545 // ----- Look if the first element is also an array 546 // This will mean that this is a file description entry 547 if (isset($p_filelist[0]) && is_array($p_filelist[0])) { 548 $v_att_list = $p_filelist; 549 } 550 551 // ----- The list is a list of string names 552 else { 553 $v_string_list = $p_filelist; 554 } 555 } 556 557 // ----- Look if the $p_filelist is a string 558 else if (is_string($p_filelist)) { 559 // ----- Create a list from the string 560 $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); 561 } 562 563 // ----- Invalid variable type for $p_filelist 564 else { 565 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); 566 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 567 return 0; 568 } 569 570 // ----- Reformat the string list 571 if (sizeof($v_string_list) != 0) { 572 foreach ($v_string_list as $v_string) { 573 $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; 574 } 575 } 576 577 // ----- For each file in the list check the attributes 578 $v_supported_attributes 579 = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' 580 ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' 581 ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' 582 ,PCLZIP_ATT_FILE_MTIME => 'optional' 583 ,PCLZIP_ATT_FILE_CONTENT => 'optional' 584 ,PCLZIP_ATT_FILE_COMMENT => 'optional' 558 585 ); 559 foreach ($v_att_list as $v_entry) {560 $v_result = $this->privFileDescrParseAtt($v_entry,561 $v_filedescr_list[],562 $v_options,563 $v_supported_attributes);564 if ($v_result != 1) {565 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);566 return 0;567 }568 }569 570 // ----- Expand the filelist (expand directories)571 $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);572 if ($v_result != 1) {573 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);574 return 0;575 }576 577 // ----- Call the create fct578 $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);579 if ($v_result != 1) {580 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);581 return 0;582 }583 584 // ----- Return585 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);586 return $p_result_list;586 foreach ($v_att_list as $v_entry) { 587 $v_result = $this->privFileDescrParseAtt($v_entry, 588 $v_filedescr_list[], 589 $v_options, 590 $v_supported_attributes); 591 if ($v_result != 1) { 592 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 593 return 0; 594 } 595 } 596 597 // ----- Expand the filelist (expand directories) 598 $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); 599 if ($v_result != 1) { 600 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 601 return 0; 602 } 603 604 // ----- Call the create fct 605 $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options); 606 if ($v_result != 1) { 607 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 608 return 0; 609 } 610 611 // ----- Return 612 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list); 613 return $p_result_list; 587 614 } 588 615 // -------------------------------------------------------------------------------- … … 594 621 // properties. 595 622 // The properties of each entries in the list are (used also in other functions) : 596 // filename : Name of the file. For a create or add action it is the filename597 // given by the user. For an extract function it is the filename598 // of the extracted file.599 // stored_filename : Name of the file / directory stored in the archive.600 // size : Size of the stored file.601 // compressed_size : Size of the file's data compressed in the archive602 // (without the headers overhead)603 // mtime : Last known modification date of the file (UNIX timestamp)604 // comment : Comment associated with the file605 // folder : true | false606 // index : index of the file in the archive607 // status : status of the action (depending of the action) :608 // Values are :609 // ok : OK !610 // filtered : the file / dir is not extracted (filtered by user)611 // already_a_directory : the file can not be extracted because a612 // directory with the same name already exists613 // write_protected : the file can not be extracted because a file614 // with the same name already exists and is615 // write protected616 // newer_exist : the file was not extracted because a newer file exists617 // path_creation_fail : the file is not extracted because the folder618 // does not existsand can not be created619 // write_error : the file was not extracted because there was a620 // error while writing the file621 // read_error : the file was not extracted because there was a error622 // while reading the file623 // invalid_header : the file was not extracted because of an archive624 // format error (bad file header)623 // filename : Name of the file. For a create or add action it is the filename 624 // given by the user. For an extract function it is the filename 625 // of the extracted file. 626 // stored_filename : Name of the file / directory stored in the archive. 627 // size : Size of the stored file. 628 // compressed_size : Size of the file's data compressed in the archive 629 // (without the headers overhead) 630 // mtime : Last known modification date of the file (UNIX timestamp) 631 // comment : Comment associated with the file 632 // folder : true | false 633 // index : index of the file in the archive 634 // status : status of the action (depending of the action) : 635 // Values are : 636 // ok : OK ! 637 // filtered : the file / dir is not extracted (filtered by user) 638 // already_a_directory : the file can not be extracted because a 639 // directory with the same name already exists 640 // write_protected : the file can not be extracted because a file 641 // with the same name already exists and is 642 // write protected 643 // newer_exist : the file was not extracted because a newer file exists 644 // path_creation_fail : the file is not extracted because the folder 645 // does not exist and can not be created 646 // write_error : the file was not extracted because there was a 647 // error while writing the file 648 // read_error : the file was not extracted because there was a error 649 // while reading the file 650 // invalid_header : the file was not extracted because of an archive 651 // format error (bad file header) 625 652 // Note that each time a method can continue operating when there 626 653 // is an action error on a file, the error is only logged in the file status. … … 631 658 function listContent() 632 659 { 633 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', "");634 $v_result=1;635 636 // ----- Reset the error handler637 $this->privErrorReset();638 639 // ----- Check archive640 if (!$this->privCheckFormat()) {641 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);642 return(0);643 }644 645 // ----- Call the extracting fct646 $p_list = array();647 if (($v_result = $this->privList($p_list)) != 1)648 {649 unset($p_list);650 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());651 return(0);652 }653 654 // ----- Return655 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);656 return $p_list;660 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', ""); 661 $v_result=1; 662 663 // ----- Reset the error handler 664 $this->privErrorReset(); 665 666 // ----- Check archive 667 if (!$this->privCheckFormat()) { 668 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 669 return(0); 670 } 671 672 // ----- Call the extracting fct 673 $p_list = array(); 674 if (($v_result = $this->privList($p_list)) != 1) 675 { 676 unset($p_list); 677 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); 678 return(0); 679 } 680 681 // ----- Return 682 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); 683 return $p_list; 657 684 } 658 685 // -------------------------------------------------------------------------------- … … 677 704 // $p_path : Path where the files and directories are to be extracted 678 705 // $p_remove_path : First part ('root' part) of the memorized path 679 // (if any similar) to remove while extracting.706 // (if any similar) to remove while extracting. 680 707 // Options : 681 708 // PCLZIP_OPT_PATH : … … 692 719 function extract() 693 720 { 694 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", "");695 $v_result=1;696 697 // ----- Reset the error handler698 $this->privErrorReset();699 700 // ----- Check archive701 if (!$this->privCheckFormat()) {702 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);703 return(0);704 }705 706 // ----- Set default values707 $v_options = array();708 // $v_path = "./";709 $v_path = '';710 $v_remove_path = "";711 $v_remove_all_path = false;712 713 // ----- Look for variable options arguments714 $v_size = func_num_args();715 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");716 717 // ----- Default values for option718 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;719 720 // ----- Look for arguments721 if ($v_size > 0) {722 // ----- Get the arguments723 $v_arg_list = func_get_args();724 725 // ----- Look for first arg726 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {727 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");728 729 // ----- Parse the options730 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,731 array (PCLZIP_OPT_PATH => 'optional',732 PCLZIP_OPT_REMOVE_PATH => 'optional',733 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',734 PCLZIP_OPT_ADD_PATH => 'optional',735 PCLZIP_CB_PRE_EXTRACT => 'optional',736 PCLZIP_CB_POST_EXTRACT => 'optional',737 PCLZIP_OPT_SET_CHMOD => 'optional',738 PCLZIP_OPT_BY_NAME => 'optional',739 PCLZIP_OPT_BY_EREG => 'optional',740 PCLZIP_OPT_BY_PREG => 'optional',741 PCLZIP_OPT_BY_INDEX => 'optional',742 PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',743 PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',744 PCLZIP_OPT_REPLACE_NEWER => 'optional'745 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'746 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'747 ));748 if ($v_result != 1) {749 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);750 return 0;751 }752 753 // ----- Set the arguments754 if (isset($v_options[PCLZIP_OPT_PATH])) {755 $v_path = $v_options[PCLZIP_OPT_PATH];756 }757 if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {758 $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];759 }760 if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {761 $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];762 }763 if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {764 // ----- Check for '/' in last path char765 if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {766 $v_path .= '/';767 }768 $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];769 }770 }771 772 // ----- Look for 2 args773 // Here we need to support the first historic synopsis of the774 // method.775 else {776 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");777 778 // ----- Get the first argument779 $v_path = $v_arg_list[0];780 781 // ----- Look for the optional second argument782 if ($v_size == 2) {783 $v_remove_path = $v_arg_list[1];784 }785 else if ($v_size > 2) {786 // ----- Error log787 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");788 789 // ----- Return790 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());791 return 0;792 }793 }794 }795 796 // ----- Trace797 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'");798 799 // ----- Call the extracting fct800 $p_list = array();801 $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,802 $v_remove_all_path, $v_options);803 if ($v_result < 1) {804 unset($p_list);805 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());806 return(0);807 }808 809 // ----- Return810 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);811 return $p_list;721 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", ""); 722 $v_result=1; 723 724 // ----- Reset the error handler 725 $this->privErrorReset(); 726 727 // ----- Check archive 728 if (!$this->privCheckFormat()) { 729 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 730 return(0); 731 } 732 733 // ----- Set default values 734 $v_options = array(); 735 // $v_path = "./"; 736 $v_path = ''; 737 $v_remove_path = ""; 738 $v_remove_all_path = false; 739 740 // ----- Look for variable options arguments 741 $v_size = func_num_args(); 742 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); 743 744 // ----- Default values for option 745 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; 746 747 // ----- Look for arguments 748 if ($v_size > 0) { 749 // ----- Get the arguments 750 $v_arg_list = func_get_args(); 751 752 // ----- Look for first arg 753 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 754 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options"); 755 756 // ----- Parse the options 757 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 758 array (PCLZIP_OPT_PATH => 'optional', 759 PCLZIP_OPT_REMOVE_PATH => 'optional', 760 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 761 PCLZIP_OPT_ADD_PATH => 'optional', 762 PCLZIP_CB_PRE_EXTRACT => 'optional', 763 PCLZIP_CB_POST_EXTRACT => 'optional', 764 PCLZIP_OPT_SET_CHMOD => 'optional', 765 PCLZIP_OPT_BY_NAME => 'optional', 766 PCLZIP_OPT_BY_EREG => 'optional', 767 PCLZIP_OPT_BY_PREG => 'optional', 768 PCLZIP_OPT_BY_INDEX => 'optional', 769 PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', 770 PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional', 771 PCLZIP_OPT_REPLACE_NEWER => 'optional' 772 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' 773 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' 774 )); 775 if ($v_result != 1) { 776 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 777 return 0; 778 } 779 780 // ----- Set the arguments 781 if (isset($v_options[PCLZIP_OPT_PATH])) { 782 $v_path = $v_options[PCLZIP_OPT_PATH]; 783 } 784 if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { 785 $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; 786 } 787 if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { 788 $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; 789 } 790 if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { 791 // ----- Check for '/' in last path char 792 if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { 793 $v_path .= '/'; 794 } 795 $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; 796 } 797 } 798 799 // ----- Look for 2 args 800 // Here we need to support the first historic synopsis of the 801 // method. 802 else { 803 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); 804 805 // ----- Get the first argument 806 $v_path = $v_arg_list[0]; 807 808 // ----- Look for the optional second argument 809 if ($v_size == 2) { 810 $v_remove_path = $v_arg_list[1]; 811 } 812 else if ($v_size > 2) { 813 // ----- Error log 814 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); 815 816 // ----- Return 817 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); 818 return 0; 819 } 820 } 821 } 822 823 // ----- Trace 824 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'"); 825 826 // ----- Call the extracting fct 827 $p_list = array(); 828 $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, 829 $v_remove_all_path, $v_options); 830 if ($v_result < 1) { 831 unset($p_list); 832 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); 833 return(0); 834 } 835 836 // ----- Return 837 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); 838 return $p_list; 812 839 } 813 840 // -------------------------------------------------------------------------------- … … 827 854 // Parameters : 828 855 // $p_index : A single index (integer) or a string of indexes of files to 829 // extract. The form of the string is "0,4-6,8-12" with only numbers830 // and '-' for range or ',' to separate ranges. No spaces or ';'831 // are allowed.856 // extract. The form of the string is "0,4-6,8-12" with only numbers 857 // and '-' for range or ',' to separate ranges. No spaces or ';' 858 // are allowed. 832 859 // $p_path : Path where the files and directories are to be extracted 833 860 // $p_remove_path : First part ('root' part) of the memorized path 834 // (if any similar) to remove while extracting.861 // (if any similar) to remove while extracting. 835 862 // Options : 836 863 // PCLZIP_OPT_PATH : … … 839 866 // PCLZIP_OPT_REMOVE_ALL_PATH : 840 867 // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and 841 // not as files.842 // The resulting content is in a new field 'content' in the file843 // structure.844 // This option must be used alone (any other options are ignored).868 // not as files. 869 // The resulting content is in a new field 'content' in the file 870 // structure. 871 // This option must be used alone (any other options are ignored). 845 872 // PCLZIP_CB_PRE_EXTRACT : 846 873 // PCLZIP_CB_POST_EXTRACT : … … 853 880 function extractByIndex($p_index) 854 881 { 855 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ...");856 $v_result=1;857 858 // ----- Reset the error handler859 $this->privErrorReset();860 861 // ----- Check archive862 if (!$this->privCheckFormat()) {863 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);864 return(0);865 }866 867 // ----- Set default values868 $v_options = array();869 // $v_path = "./";870 $v_path = '';871 $v_remove_path = "";872 $v_remove_all_path = false;873 874 // ----- Look for variable options arguments875 $v_size = func_num_args();876 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");877 878 // ----- Default values for option879 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;880 881 // ----- Look for arguments882 if ($v_size > 1) {883 // ----- Get the arguments884 $v_arg_list = func_get_args();885 886 // ----- Remove form the options list the first argument887 array_shift($v_arg_list);888 $v_size--;889 890 // ----- Look for first arg891 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {892 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");893 894 // ----- Parse the options895 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,896 array (PCLZIP_OPT_PATH => 'optional',897 PCLZIP_OPT_REMOVE_PATH => 'optional',898 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',899 PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',900 PCLZIP_OPT_ADD_PATH => 'optional',901 PCLZIP_CB_PRE_EXTRACT => 'optional',902 PCLZIP_CB_POST_EXTRACT => 'optional',903 PCLZIP_OPT_SET_CHMOD => 'optional',904 PCLZIP_OPT_REPLACE_NEWER => 'optional'905 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'906 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'882 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ..."); 883 $v_result=1; 884 885 // ----- Reset the error handler 886 $this->privErrorReset(); 887 888 // ----- Check archive 889 if (!$this->privCheckFormat()) { 890 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 891 return(0); 892 } 893 894 // ----- Set default values 895 $v_options = array(); 896 // $v_path = "./"; 897 $v_path = ''; 898 $v_remove_path = ""; 899 $v_remove_all_path = false; 900 901 // ----- Look for variable options arguments 902 $v_size = func_num_args(); 903 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); 904 905 // ----- Default values for option 906 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; 907 908 // ----- Look for arguments 909 if ($v_size > 1) { 910 // ----- Get the arguments 911 $v_arg_list = func_get_args(); 912 913 // ----- Remove form the options list the first argument 914 array_shift($v_arg_list); 915 $v_size--; 916 917 // ----- Look for first arg 918 if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { 919 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options"); 920 921 // ----- Parse the options 922 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 923 array (PCLZIP_OPT_PATH => 'optional', 924 PCLZIP_OPT_REMOVE_PATH => 'optional', 925 PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', 926 PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', 927 PCLZIP_OPT_ADD_PATH => 'optional', 928 PCLZIP_CB_PRE_EXTRACT => 'optional', 929 PCLZIP_CB_POST_EXTRACT => 'optional', 930 PCLZIP_OPT_SET_CHMOD => 'optional', 931 PCLZIP_OPT_REPLACE_NEWER => 'optional' 932 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' 933 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' 907 934 )); 908 if ($v_result != 1) {909 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);910 return 0;911 }912 913 // ----- Set the arguments914 if (isset($v_options[PCLZIP_OPT_PATH])) {915 $v_path = $v_options[PCLZIP_OPT_PATH];916 }917 if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {918 $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];919 }920 if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {921 $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];922 }923 if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {924 // ----- Check for '/' in last path char925 if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {926 $v_path .= '/';927 }928 $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];929 }930 if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {931 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;932 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING not set.");933 }934 else {935 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING set.");936 }937 }938 939 // ----- Look for 2 args940 // Here we need to support the first historic synopsis of the941 // method.942 else {943 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");944 945 // ----- Get the first argument946 $v_path = $v_arg_list[0];947 948 // ----- Look for the optional second argument949 if ($v_size == 2) {950 $v_remove_path = $v_arg_list[1];951 }952 else if ($v_size > 2) {953 // ----- Error log954 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");955 956 // ----- Return957 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());958 return 0;959 }960 }961 }962 963 // ----- Trace964 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "index='$p_index', path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'");965 966 // ----- Trick967 // Here I want to reuse extractByRule(), so I need to parse the $p_index968 // with privParseOptions()969 $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);970 $v_options_trick = array();971 $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,972 array (PCLZIP_OPT_BY_INDEX => 'optional' ));973 if ($v_result != 1) {974 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);975 return 0;976 }977 $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];978 979 // ----- Call the extracting fct980 if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {981 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());982 return(0);983 }984 985 // ----- Return986 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);987 return $p_list;935 if ($v_result != 1) { 936 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 937 return 0; 938 } 939 940 // ----- Set the arguments 941 if (isset($v_options[PCLZIP_OPT_PATH])) { 942 $v_path = $v_options[PCLZIP_OPT_PATH]; 943 } 944 if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { 945 $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; 946 } 947 if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { 948 $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; 949 } 950 if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { 951 // ----- Check for '/' in last path char 952 if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { 953 $v_path .= '/'; 954 } 955 $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; 956 } 957 if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { 958 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; 959 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING not set."); 960 } 961 else { 962 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING set."); 963 } 964 } 965 966 // ----- Look for 2 args 967 // Here we need to support the first historic synopsis of the 968 // method. 969 else { 970 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); 971 972 // ----- Get the first argument 973 $v_path = $v_arg_list[0]; 974 975 // ----- Look for the optional second argument 976 if ($v_size == 2) { 977 $v_remove_path = $v_arg_list[1]; 978 } 979 else if ($v_size > 2) { 980 // ----- Error log 981 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); 982 983 // ----- Return 984 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 985 return 0; 986 } 987 } 988 } 989 990 // ----- Trace 991 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "index='$p_index', path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'"); 992 993 // ----- Trick 994 // Here I want to reuse extractByRule(), so I need to parse the $p_index 995 // with privParseOptions() 996 $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index); 997 $v_options_trick = array(); 998 $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, 999 array (PCLZIP_OPT_BY_INDEX => 'optional' )); 1000 if ($v_result != 1) { 1001 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 1002 return 0; 1003 } 1004 $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX]; 1005 1006 // ----- Call the extracting fct 1007 if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) { 1008 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); 1009 return(0); 1010 } 1011 1012 // ----- Return 1013 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); 1014 return $p_list; 988 1015 } 989 1016 // -------------------------------------------------------------------------------- … … 1000 1027 // PCLZIP_OPT_BY_INDEX : 1001 1028 // PCLZIP_OPT_BY_NAME : 1002 // PCLZIP_OPT_BY_EREG : 1029 // PCLZIP_OPT_BY_EREG : 1003 1030 // PCLZIP_OPT_BY_PREG : 1004 1031 // Return Values : … … 1009 1036 function delete() 1010 1037 { 1011 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", "");1012 $v_result=1;1013 1014 // ----- Reset the error handler1015 $this->privErrorReset();1016 1017 // ----- Check archive1018 if (!$this->privCheckFormat()) {1019 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);1020 return(0);1021 }1022 1023 // ----- Set default values1024 $v_options = array();1025 1026 // ----- Look for variable options arguments1027 $v_size = func_num_args();1028 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");1029 1030 // ----- Look for arguments1031 if ($v_size > 0) {1032 // ----- Get the arguments1033 $v_arg_list = func_get_args();1034 1035 // ----- Parse the options1036 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,1037 array (PCLZIP_OPT_BY_NAME => 'optional',1038 PCLZIP_OPT_BY_EREG => 'optional',1039 PCLZIP_OPT_BY_PREG => 'optional',1040 PCLZIP_OPT_BY_INDEX => 'optional' ));1041 if ($v_result != 1) {1042 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);1043 return 0;1044 }1045 }1046 1047 // ----- Magic quotes trick1048 $this->privDisableMagicQuotes();1049 1050 // ----- Call the delete fct1051 $v_list = array();1052 if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {1053 $this->privSwapBackMagicQuotes();1054 unset($v_list);1055 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());1056 return(0);1057 }1058 1059 // ----- Magic quotes trick1060 $this->privSwapBackMagicQuotes();1061 1062 // ----- Return1063 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list);1064 return $v_list;1038 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", ""); 1039 $v_result=1; 1040 1041 // ----- Reset the error handler 1042 $this->privErrorReset(); 1043 1044 // ----- Check archive 1045 if (!$this->privCheckFormat()) { 1046 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 1047 return(0); 1048 } 1049 1050 // ----- Set default values 1051 $v_options = array(); 1052 1053 // ----- Look for variable options arguments 1054 $v_size = func_num_args(); 1055 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); 1056 1057 // ----- Look for arguments 1058 if ($v_size > 0) { 1059 // ----- Get the arguments 1060 $v_arg_list = func_get_args(); 1061 1062 // ----- Parse the options 1063 $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, 1064 array (PCLZIP_OPT_BY_NAME => 'optional', 1065 PCLZIP_OPT_BY_EREG => 'optional', 1066 PCLZIP_OPT_BY_PREG => 'optional', 1067 PCLZIP_OPT_BY_INDEX => 'optional' )); 1068 if ($v_result != 1) { 1069 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 1070 return 0; 1071 } 1072 } 1073 1074 // ----- Magic quotes trick 1075 $this->privDisableMagicQuotes(); 1076 1077 // ----- Call the delete fct 1078 $v_list = array(); 1079 if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) { 1080 $this->privSwapBackMagicQuotes(); 1081 unset($v_list); 1082 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); 1083 return(0); 1084 } 1085 1086 // ----- Magic quotes trick 1087 $this->privSwapBackMagicQuotes(); 1088 1089 // ----- Return 1090 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list); 1091 return $v_list; 1065 1092 } 1066 1093 // -------------------------------------------------------------------------------- … … 1074 1101 function deleteByIndex($p_index) 1075 1102 { 1076 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'");1077 1078 $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);1079 1080 // ----- Return1081 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);1082 return $p_list;1103 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'"); 1104 1105 $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); 1106 1107 // ----- Return 1108 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); 1109 return $p_list; 1083 1110 } 1084 1111 // -------------------------------------------------------------------------------- … … 1089 1116 // This method gives the properties of the archive. 1090 1117 // The properties are : 1091 // nb : Number of files in the archive1092 // comment : Comment associated with the archive file1093 // status : not_exist, ok1118 // nb : Number of files in the archive 1119 // comment : Comment associated with the archive file 1120 // status : not_exist, ok 1094 1121 // Parameters : 1095 1122 // None … … 1100 1127 function properties() 1101 1128 { 1102 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", "");1103 1104 // ----- Reset the error handler1105 $this->privErrorReset();1106 1107 // ----- Magic quotes trick1108 $this->privDisableMagicQuotes();1109 1110 // ----- Check archive1111 if (!$this->privCheckFormat()) {1112 $this->privSwapBackMagicQuotes();1113 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);1114 return(0);1115 }1116 1117 // ----- Default properties1118 $v_prop = array();1119 $v_prop['comment'] = '';1120 $v_prop['nb'] = 0;1121 $v_prop['status'] = 'not_exist';1122 1123 // ----- Look if file exists1124 if (@is_file($this->zipname))1125 {1126 // ----- Open the zip file1127 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");1128 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)1129 {1130 $this->privSwapBackMagicQuotes();1131 1132 // ----- Error log1133 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');1134 1135 // ----- Return1136 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0);1137 return 0;1138 }1139 1140 // ----- Read the central directory informations1141 $v_central_dir = array();1142 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)1143 {1144 $this->privSwapBackMagicQuotes();1145 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);1146 return 0;1147 }1148 1149 // ----- Close the zip file1150 $this->privCloseFd();1151 1152 // ----- Set the user attributes1153 $v_prop['comment'] = $v_central_dir['comment'];1154 $v_prop['nb'] = $v_central_dir['entries'];1155 $v_prop['status'] = 'ok';1156 }1157 1158 // ----- Magic quotes trick1159 $this->privSwapBackMagicQuotes();1160 1161 // ----- Return1162 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop);1163 return $v_prop;1129 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", ""); 1130 1131 // ----- Reset the error handler 1132 $this->privErrorReset(); 1133 1134 // ----- Magic quotes trick 1135 $this->privDisableMagicQuotes(); 1136 1137 // ----- Check archive 1138 if (!$this->privCheckFormat()) { 1139 $this->privSwapBackMagicQuotes(); 1140 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 1141 return(0); 1142 } 1143 1144 // ----- Default properties 1145 $v_prop = array(); 1146 $v_prop['comment'] = ''; 1147 $v_prop['nb'] = 0; 1148 $v_prop['status'] = 'not_exist'; 1149 1150 // ----- Look if file exists 1151 if (@is_file($this->zipname)) 1152 { 1153 // ----- Open the zip file 1154 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 1155 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) 1156 { 1157 $this->privSwapBackMagicQuotes(); 1158 1159 // ----- Error log 1160 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); 1161 1162 // ----- Return 1163 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0); 1164 return 0; 1165 } 1166 1167 // ----- Read the central directory informations 1168 $v_central_dir = array(); 1169 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 1170 { 1171 $this->privSwapBackMagicQuotes(); 1172 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 1173 return 0; 1174 } 1175 1176 // ----- Close the zip file 1177 $this->privCloseFd(); 1178 1179 // ----- Set the user attributes 1180 $v_prop['comment'] = $v_central_dir['comment']; 1181 $v_prop['nb'] = $v_central_dir['entries']; 1182 $v_prop['status'] = 'ok'; 1183 } 1184 1185 // ----- Magic quotes trick 1186 $this->privSwapBackMagicQuotes(); 1187 1188 // ----- Return 1189 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop); 1190 return $v_prop; 1164 1191 } 1165 1192 // -------------------------------------------------------------------------------- … … 1172 1199 // Parameters : 1173 1200 // $p_archive : The filename of a valid archive, or 1174 // a valid PclZip object.1201 // a valid PclZip object. 1175 1202 // Return Values : 1176 1203 // 1 on success. … … 1179 1206 function duplicate($p_archive) 1180 1207 { 1181 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", "");1182 $v_result = 1;1183 1184 // ----- Reset the error handler1185 $this->privErrorReset();1186 1187 // ----- Look if the $p_archive is a PclZip object1188 if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))1189 {1190 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'");1191 1192 // ----- Duplicate the archive1193 $v_result = $this->privDuplicate($p_archive->zipname);1194 }1195 1196 // ----- Look if the $p_archive is a string (so a filename)1197 else if (is_string($p_archive))1198 {1199 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'");1200 1201 // ----- Check that $p_archive is a valid zip file1202 // TBC : Should also check the archive format1203 if (!is_file($p_archive)) {1204 // ----- Error log1205 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");1206 $v_result = PCLZIP_ERR_MISSING_FILE;1207 }1208 else {1209 // ----- Duplicate the archive1210 $v_result = $this->privDuplicate($p_archive);1211 }1212 }1213 1214 // ----- Invalid variable1215 else1216 {1217 // ----- Error log1218 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");1219 $v_result = PCLZIP_ERR_INVALID_PARAMETER;1220 }1221 1222 // ----- Return1223 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);1224 return $v_result;1208 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", ""); 1209 $v_result = 1; 1210 1211 // ----- Reset the error handler 1212 $this->privErrorReset(); 1213 1214 // ----- Look if the $p_archive is a PclZip object 1215 if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) 1216 { 1217 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'"); 1218 1219 // ----- Duplicate the archive 1220 $v_result = $this->privDuplicate($p_archive->zipname); 1221 } 1222 1223 // ----- Look if the $p_archive is a string (so a filename) 1224 else if (is_string($p_archive)) 1225 { 1226 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'"); 1227 1228 // ----- Check that $p_archive is a valid zip file 1229 // TBC : Should also check the archive format 1230 if (!is_file($p_archive)) { 1231 // ----- Error log 1232 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'"); 1233 $v_result = PCLZIP_ERR_MISSING_FILE; 1234 } 1235 else { 1236 // ----- Duplicate the archive 1237 $v_result = $this->privDuplicate($p_archive); 1238 } 1239 } 1240 1241 // ----- Invalid variable 1242 else 1243 { 1244 // ----- Error log 1245 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); 1246 $v_result = PCLZIP_ERR_INVALID_PARAMETER; 1247 } 1248 1249 // ----- Return 1250 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1251 return $v_result; 1225 1252 } 1226 1253 // -------------------------------------------------------------------------------- … … 1235 1262 // Parameters : 1236 1263 // $p_archive_to_add : It can be directly the filename of a valid zip archive, 1237 // or a PclZip object archive.1264 // or a PclZip object archive. 1238 1265 // Return Values : 1239 1266 // 1 on success, … … 1242 1269 function merge($p_archive_to_add) 1243 1270 { 1244 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", "");1245 $v_result = 1;1246 1247 // ----- Reset the error handler1248 $this->privErrorReset();1249 1250 // ----- Check archive1251 if (!$this->privCheckFormat()) {1252 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);1253 return(0);1254 }1255 1256 // ----- Look if the $p_archive_to_add is a PclZip object1257 if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))1258 {1259 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object");1260 1261 // ----- Merge the archive1262 $v_result = $this->privMerge($p_archive_to_add);1263 }1264 1265 // ----- Look if the $p_archive_to_add is a string (so a filename)1266 else if (is_string($p_archive_to_add))1267 {1268 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename");1269 1270 // ----- Create a temporary archive1271 $v_object_archive = new PclZip($p_archive_to_add);1272 1273 // ----- Merge the archive1274 $v_result = $this->privMerge($v_object_archive);1275 }1276 1277 // ----- Invalid variable1278 else1279 {1280 // ----- Error log1281 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");1282 $v_result = PCLZIP_ERR_INVALID_PARAMETER;1283 }1284 1285 // ----- Return1286 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);1287 return $v_result;1271 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", ""); 1272 $v_result = 1; 1273 1274 // ----- Reset the error handler 1275 $this->privErrorReset(); 1276 1277 // ----- Check archive 1278 if (!$this->privCheckFormat()) { 1279 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 1280 return(0); 1281 } 1282 1283 // ----- Look if the $p_archive_to_add is a PclZip object 1284 if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) 1285 { 1286 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object"); 1287 1288 // ----- Merge the archive 1289 $v_result = $this->privMerge($p_archive_to_add); 1290 } 1291 1292 // ----- Look if the $p_archive_to_add is a string (so a filename) 1293 else if (is_string($p_archive_to_add)) 1294 { 1295 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename"); 1296 1297 // ----- Create a temporary archive 1298 $v_object_archive = new PclZip($p_archive_to_add); 1299 1300 // ----- Merge the archive 1301 $v_result = $this->privMerge($v_object_archive); 1302 } 1303 1304 // ----- Invalid variable 1305 else 1306 { 1307 // ----- Error log 1308 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); 1309 $v_result = PCLZIP_ERR_INVALID_PARAMETER; 1310 } 1311 1312 // ----- Return 1313 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1314 return $v_result; 1288 1315 } 1289 1316 // -------------------------------------------------------------------------------- … … 1298 1325 function errorCode() 1299 1326 { 1300 if (PCLZIP_ERROR_EXTERNAL == 1) {1301 return(PclErrorCode());1302 }1303 else {1304 return($this->error_code);1305 }1327 if (PCLZIP_ERROR_EXTERNAL == 1) { 1328 return(PclErrorCode()); 1329 } 1330 else { 1331 return($this->error_code); 1332 } 1306 1333 } 1307 1334 // -------------------------------------------------------------------------------- … … 1314 1341 function errorName($p_with_code=false) 1315 1342 { 1316 $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',1317 PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',1318 PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',1319 PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',1320 PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',1321 PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',1322 PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',1323 PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',1324 PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',1325 PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',1326 PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',1327 PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',1328 PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',1329 PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',1330 PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',1331 PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',1332 PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',1333 PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',1334 PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION' 1335 ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE' 1336 ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'1337 );1338 1339 if (isset($v_name[$this->error_code])) {1340 $v_value = $v_name[$this->error_code];1341 }1342 else {1343 $v_value = 'NoName';1344 }1345 1346 if ($p_with_code) {1347 return($v_value.' ('.$this->error_code.')');1348 }1349 else {1350 return($v_value);1351 }1343 $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', 1344 PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', 1345 PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', 1346 PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', 1347 PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE', 1348 PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG', 1349 PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP', 1350 PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE', 1351 PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL', 1352 PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION', 1353 PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT', 1354 PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL', 1355 PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL', 1356 PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM', 1357 PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', 1358 PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE', 1359 PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE', 1360 PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', 1361 PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', 1362 PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', 1363 PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION' 1364 ); 1365 1366 if (isset($v_name[$this->error_code])) { 1367 $v_value = $v_name[$this->error_code]; 1368 } 1369 else { 1370 $v_value = 'NoName'; 1371 } 1372 1373 if ($p_with_code) { 1374 return($v_value.' ('.$this->error_code.')'); 1375 } 1376 else { 1377 return($v_value); 1378 } 1352 1379 } 1353 1380 // -------------------------------------------------------------------------------- … … 1360 1387 function errorInfo($p_full=false) 1361 1388 { 1362 if (PCLZIP_ERROR_EXTERNAL == 1) {1363 return(PclErrorString());1364 }1365 else {1366 if ($p_full) {1367 return($this->errorName(true)." : ".$this->error_string);1368 }1369 else {1370 return($this->error_string." [code ".$this->error_code."]");1371 }1372 }1389 if (PCLZIP_ERROR_EXTERNAL == 1) { 1390 return(PclErrorString()); 1391 } 1392 else { 1393 if ($p_full) { 1394 return($this->errorName(true)." : ".$this->error_string); 1395 } 1396 else { 1397 return($this->error_string." [code ".$this->error_code."]"); 1398 } 1399 } 1373 1400 } 1374 1401 // -------------------------------------------------------------------------------- … … 1377 1404 // -------------------------------------------------------------------------------- 1378 1405 // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS ***** 1379 // ***** ***** 1380 // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY ***** 1406 // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY ***** 1381 1407 // -------------------------------------------------------------------------------- 1382 1408 … … 1390 1416 // Parameters : 1391 1417 // $p_level : Level of check. Default 0. 1392 // 0 : Check the first bytes (magic codes) (default value))1393 // 1 : 0 + Check the central directory (futur)1394 // 2 : 1 + Check each file header (futur)1418 // 0 : Check the first bytes (magic codes) (default value)) 1419 // 1 : 0 + Check the central directory (futur) 1420 // 2 : 1 + Check each file header (futur) 1395 1421 // Return Values : 1396 1422 // true on success, … … 1399 1425 function privCheckFormat($p_level=0) 1400 1426 { 1401 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", "");1402 $v_result = true;1427 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", ""); 1428 $v_result = true; 1403 1429 1404 1430 // ----- Reset the file system cache 1405 clearstatcache();1406 1407 // ----- Reset the error handler1408 $this->privErrorReset();1409 1410 // ----- Look if the file exits1411 if (!is_file($this->zipname)) {1412 // ----- Error log1413 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");1414 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());1415 return(false);1416 }1417 1418 // ----- Check that the file is readeable1419 if (!is_readable($this->zipname)) {1420 // ----- Error log1421 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");1422 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());1423 return(false);1424 }1425 1426 // ----- Check the magic code1427 // TBC1428 1429 // ----- Check the central header1430 // TBC1431 1432 // ----- Check each file header1433 // TBC1434 1435 // ----- Return1436 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);1437 return $v_result;1431 clearstatcache(); 1432 1433 // ----- Reset the error handler 1434 $this->privErrorReset(); 1435 1436 // ----- Look if the file exits 1437 if (!is_file($this->zipname)) { 1438 // ----- Error log 1439 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); 1440 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo()); 1441 return(false); 1442 } 1443 1444 // ----- Check that the file is readeable 1445 if (!is_readable($this->zipname)) { 1446 // ----- Error log 1447 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); 1448 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo()); 1449 return(false); 1450 } 1451 1452 // ----- Check the magic code 1453 // TBC 1454 1455 // ----- Check the central header 1456 // TBC 1457 1458 // ----- Check each file header 1459 // TBC 1460 1461 // ----- Return 1462 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1463 return $v_result; 1438 1464 } 1439 1465 // -------------------------------------------------------------------------------- … … 1456 1482 function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) 1457 1483 { 1458 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", ""); 1459 $v_result=1; 1460 1461 // ----- Read the options 1462 $i=0; 1463 while ($i<$p_size) { 1464 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'"); 1465 1466 // ----- Check if the option is supported 1467 if (!isset($v_requested_options[$p_options_list[$i]])) { 1468 // ----- Error log 1469 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); 1470 1471 // ----- Return 1472 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1473 return PclZip::errorCode(); 1474 } 1475 1476 // ----- Look for next option 1477 switch ($p_options_list[$i]) { 1478 // ----- Look for options that request a path value 1479 case PCLZIP_OPT_PATH : 1480 case PCLZIP_OPT_REMOVE_PATH : 1481 case PCLZIP_OPT_ADD_PATH : 1482 // ----- Check the number of parameters 1483 if (($i+1) >= $p_size) { 1484 // ----- Error log 1485 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1486 1487 // ----- Return 1488 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1489 return PclZip::errorCode(); 1490 } 1491 1492 // ----- Get the value 1493 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false); 1494 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1495 $i++; 1496 break; 1497 1498 case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : 1499 // ----- Check the number of parameters 1500 if (($i+1) >= $p_size) { 1501 // ----- Error log 1502 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1503 1504 // ----- Return 1505 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1506 return PclZip::errorCode(); 1507 } 1508 1509 // ----- Get the value 1510 if ( is_string($p_options_list[$i+1]) 1511 && ($p_options_list[$i+1] != '')) { 1512 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false); 1513 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1514 $i++; 1515 } 1516 else { 1517 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored."); 1518 } 1519 break; 1520 1521 // ----- Look for options that request an array of string for value 1522 case PCLZIP_OPT_BY_NAME : 1523 // ----- Check the number of parameters 1524 if (($i+1) >= $p_size) { 1525 // ----- Error log 1526 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1527 1528 // ----- Return 1529 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1530 return PclZip::errorCode(); 1531 } 1532 1533 // ----- Get the value 1534 if (is_string($p_options_list[$i+1])) { 1535 $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; 1536 } 1537 else if (is_array($p_options_list[$i+1])) { 1538 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1539 } 1540 else { 1541 // ----- Error log 1542 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1543 1544 // ----- Return 1545 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1546 return PclZip::errorCode(); 1547 } 1548 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1549 $i++; 1550 break; 1551 1552 // ----- Look for options that request an EREG or PREG expression 1553 case PCLZIP_OPT_BY_EREG : 1554 case PCLZIP_OPT_BY_PREG : 1555 //case PCLZIP_OPT_CRYPT : 1556 // ----- Check the number of parameters 1557 if (($i+1) >= $p_size) { 1558 // ----- Error log 1559 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1560 1561 // ----- Return 1562 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1563 return PclZip::errorCode(); 1564 } 1565 1566 // ----- Get the value 1567 if (is_string($p_options_list[$i+1])) { 1568 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1569 } 1570 else { 1571 // ----- Error log 1572 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1573 1574 // ----- Return 1575 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1576 return PclZip::errorCode(); 1577 } 1578 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1579 $i++; 1580 break; 1581 1582 // ----- Look for options that takes a string 1583 case PCLZIP_OPT_COMMENT : 1584 case PCLZIP_OPT_ADD_COMMENT : 1585 case PCLZIP_OPT_PREPEND_COMMENT : 1586 // ----- Check the number of parameters 1587 if (($i+1) >= $p_size) { 1588 // ----- Error log 1589 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, 1590 "Missing parameter value for option '" 1484 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", ""); 1485 $v_result=1; 1486 1487 // ----- Read the options 1488 $i=0; 1489 while ($i<$p_size) { 1490 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'"); 1491 1492 // ----- Check if the option is supported 1493 if (!isset($v_requested_options[$p_options_list[$i]])) { 1494 // ----- Error log 1495 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); 1496 1497 // ----- Return 1498 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1499 return PclZip::errorCode(); 1500 } 1501 1502 // ----- Look for next option 1503 switch ($p_options_list[$i]) { 1504 // ----- Look for options that request a path value 1505 case PCLZIP_OPT_PATH : 1506 case PCLZIP_OPT_REMOVE_PATH : 1507 case PCLZIP_OPT_ADD_PATH : 1508 // ----- Check the number of parameters 1509 if (($i+1) >= $p_size) { 1510 // ----- Error log 1511 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1512 1513 // ----- Return 1514 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1515 return PclZip::errorCode(); 1516 } 1517 1518 // ----- Get the value 1519 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); 1520 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1521 $i++; 1522 break; 1523 1524 case PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD : 1525 // ----- Check the number of parameters 1526 if (($i+1) >= $p_size) { 1527 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1528 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1529 return PclZip::errorCode(); 1530 } 1531 1532 // ----- Check for incompatible options 1533 if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_OFF])) { 1534 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_OFF'"); 1535 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1536 return PclZip::errorCode(); 1537 } 1538 1539 // ----- Check the value 1540 $v_value = $p_options_list[$i+1]; 1541 if ((!is_integer($v_value)) || ($v_value<0)) { 1542 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1543 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1544 return PclZip::errorCode(); 1545 } 1546 1547 // ----- Get the value (and convert it in bytes) 1548 $v_result_list[$p_options_list[$i]] = $v_value*1048576; 1549 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1550 $i++; 1551 break; 1552 1553 case PCLZIP_OPT_ADD_TEMP_FILE_ON : 1554 // ----- Check for incompatible options 1555 if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_OFF])) { 1556 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_OFF'"); 1557 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1558 return PclZip::errorCode(); 1559 } 1560 1561 $v_result_list[$p_options_list[$i]] = true; 1562 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1563 break; 1564 1565 case PCLZIP_OPT_ADD_TEMP_FILE_OFF : 1566 // ----- Check for incompatible options 1567 if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_ON])) { 1568 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_ON'"); 1569 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1570 return PclZip::errorCode(); 1571 } 1572 // ----- Check for incompatible options 1573 if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) { 1574 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD'"); 1575 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1576 return PclZip::errorCode(); 1577 } 1578 1579 $v_result_list[$p_options_list[$i]] = true; 1580 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1581 break; 1582 1583 case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : 1584 // ----- Check the number of parameters 1585 if (($i+1) >= $p_size) { 1586 // ----- Error log 1587 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1588 1589 // ----- Return 1590 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1591 return PclZip::errorCode(); 1592 } 1593 1594 // ----- Get the value 1595 if ( is_string($p_options_list[$i+1]) 1596 && ($p_options_list[$i+1] != '')) { 1597 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); 1598 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1599 $i++; 1600 } 1601 else { 1602 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored."); 1603 } 1604 break; 1605 1606 // ----- Look for options that request an array of string for value 1607 case PCLZIP_OPT_BY_NAME : 1608 // ----- Check the number of parameters 1609 if (($i+1) >= $p_size) { 1610 // ----- Error log 1611 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1612 1613 // ----- Return 1614 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1615 return PclZip::errorCode(); 1616 } 1617 1618 // ----- Get the value 1619 if (is_string($p_options_list[$i+1])) { 1620 $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; 1621 } 1622 else if (is_array($p_options_list[$i+1])) { 1623 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1624 } 1625 else { 1626 // ----- Error log 1627 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1628 1629 // ----- Return 1630 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1631 return PclZip::errorCode(); 1632 } 1633 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1634 $i++; 1635 break; 1636 1637 // ----- Look for options that request an EREG or PREG expression 1638 case PCLZIP_OPT_BY_EREG : 1639 case PCLZIP_OPT_BY_PREG : 1640 //case PCLZIP_OPT_CRYPT : 1641 // ----- Check the number of parameters 1642 if (($i+1) >= $p_size) { 1643 // ----- Error log 1644 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1645 1646 // ----- Return 1647 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1648 return PclZip::errorCode(); 1649 } 1650 1651 // ----- Get the value 1652 if (is_string($p_options_list[$i+1])) { 1653 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1654 } 1655 else { 1656 // ----- Error log 1657 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1658 1659 // ----- Return 1660 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1661 return PclZip::errorCode(); 1662 } 1663 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1664 $i++; 1665 break; 1666 1667 // ----- Look for options that takes a string 1668 case PCLZIP_OPT_COMMENT : 1669 case PCLZIP_OPT_ADD_COMMENT : 1670 case PCLZIP_OPT_PREPEND_COMMENT : 1671 // ----- Check the number of parameters 1672 if (($i+1) >= $p_size) { 1673 // ----- Error log 1674 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, 1675 "Missing parameter value for option '" 1591 1676 .PclZipUtilOptionText($p_options_list[$i]) 1592 1677 ."'"); 1593 1678 1594 // ----- Return1595 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1596 return PclZip::errorCode();1597 }1598 1599 // ----- Get the value1600 if (is_string($p_options_list[$i+1])) {1601 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];1602 }1603 else {1604 // ----- Error log1605 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,1606 "Wrong parameter value for option '"1679 // ----- Return 1680 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1681 return PclZip::errorCode(); 1682 } 1683 1684 // ----- Get the value 1685 if (is_string($p_options_list[$i+1])) { 1686 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1687 } 1688 else { 1689 // ----- Error log 1690 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, 1691 "Wrong parameter value for option '" 1607 1692 .PclZipUtilOptionText($p_options_list[$i]) 1608 1693 ."'"); 1609 1694 1610 // ----- Return1611 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1612 return PclZip::errorCode();1613 }1614 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");1615 $i++;1616 break;1617 1618 // ----- Look for options that request an array of index1619 case PCLZIP_OPT_BY_INDEX :1620 // ----- Check the number of parameters1621 if (($i+1) >= $p_size) {1622 // ----- Error log1623 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");1624 1625 // ----- Return1626 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1627 return PclZip::errorCode();1628 }1629 1630 // ----- Get the value1631 $v_work_list = array();1632 if (is_string($p_options_list[$i+1])) {1633 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'");1634 1635 // ----- Remove spaces1636 $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');1637 1638 // ----- Parse items1639 $v_work_list = explode(",", $p_options_list[$i+1]);1640 }1641 else if (is_integer($p_options_list[$i+1])) {1642 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an integer '".$p_options_list[$i+1]."'");1643 $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];1644 }1645 else if (is_array($p_options_list[$i+1])) {1646 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array");1647 $v_work_list = $p_options_list[$i+1];1648 }1649 else {1650 // ----- Error log1651 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");1652 1653 // ----- Return1654 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1655 return PclZip::errorCode();1656 }1657 1658 // ----- Reduce the index list1659 // each index item in the list must be a couple with a start and1660 // an end value : [0,3], [5-5], [8-10], ...1661 // ----- Check the format of each item1662 $v_sort_flag=false;1663 $v_sort_value=0;1664 for ($j=0; $j<sizeof($v_work_list); $j++) {1665 // ----- Explode the item1666 $v_item_list = explode("-", $v_work_list[$j]);1667 $v_size_item_list = sizeof($v_item_list);1668 1669 // ----- TBC : Here we might check that each item is a1670 // real integer ...1671 1672 // ----- Look for single value1673 if ($v_size_item_list == 1) {1674 // ----- Set the option value1675 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];1676 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];1677 }1678 elseif ($v_size_item_list == 2) {1679 // ----- Set the option value1680 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];1681 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];1682 }1683 else {1684 // ----- Error log1685 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");1686 1687 // ----- Return1688 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1689 return PclZip::errorCode();1690 }1691 1692 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extracted index item = [".$v_result_list[$p_options_list[$i]][$j]['start'].",".$v_result_list[$p_options_list[$i]][$j]['end']."]");1693 1694 // ----- Look for list sort1695 if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {1696 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The list should be sorted ...");1697 $v_sort_flag=true;1698 1699 // ----- TBC : An automatic sort should be writen ...1700 // ----- Error log1701 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");1702 1703 // ----- Return1704 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1705 return PclZip::errorCode();1706 }1707 $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];1708 }1709 1710 // ----- Sort the items1711 if ($v_sort_flag) {1712 // TBC : To Be Completed1713 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ...");1714 }1715 1716 // ----- Next option1717 $i++;1718 break;1719 1720 // ----- Look for options that request no value1721 case PCLZIP_OPT_REMOVE_ALL_PATH :1722 case PCLZIP_OPT_EXTRACT_AS_STRING :1723 case PCLZIP_OPT_NO_COMPRESSION :1724 case PCLZIP_OPT_EXTRACT_IN_OUTPUT :1725 case PCLZIP_OPT_REPLACE_NEWER :1726 case PCLZIP_OPT_STOP_ON_ERROR :1727 $v_result_list[$p_options_list[$i]] = true;1728 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");1729 break;1730 1731 // ----- Look for options that request an octal value1732 case PCLZIP_OPT_SET_CHMOD :1733 // ----- Check the number of parameters1734 if (($i+1) >= $p_size) {1735 // ----- Error log1736 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");1737 1738 // ----- Return1739 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1740 return PclZip::errorCode();1741 }1742 1743 // ----- Get the value1744 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];1745 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");1746 $i++;1747 break;1748 1749 // ----- Look for options that request a call-back1750 case PCLZIP_CB_PRE_EXTRACT :1751 case PCLZIP_CB_POST_EXTRACT :1752 case PCLZIP_CB_PRE_ADD :1753 case PCLZIP_CB_POST_ADD :1754 /* for futur use1755 case PCLZIP_CB_PRE_DELETE :1756 case PCLZIP_CB_POST_DELETE :1757 case PCLZIP_CB_PRE_LIST :1758 case PCLZIP_CB_POST_LIST :1759 */1760 // ----- Check the number of parameters1761 if (($i+1) >= $p_size) {1762 // ----- Error log1763 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");1764 1765 // ----- Return1766 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1767 return PclZip::errorCode();1768 }1769 1770 // ----- Get the value1771 $v_function_name = $p_options_list[$i+1];1772 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "call-back ".PclZipUtilOptionText($p_options_list[$i])." = '".$v_function_name."'");1773 1774 // ----- Check that the value is a valid existing function1775 if (!function_exists($v_function_name)) {1776 // ----- Error log1777 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");1778 1779 // ----- Return1780 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1781 return PclZip::errorCode();1782 }1783 1784 // ----- Set the attribute1785 $v_result_list[$p_options_list[$i]] = $v_function_name;1786 $i++;1787 break;1788 1789 default :1790 // ----- Error log1791 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,1792 "Unknown parameter '"1695 // ----- Return 1696 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1697 return PclZip::errorCode(); 1698 } 1699 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1700 $i++; 1701 break; 1702 1703 // ----- Look for options that request an array of index 1704 case PCLZIP_OPT_BY_INDEX : 1705 // ----- Check the number of parameters 1706 if (($i+1) >= $p_size) { 1707 // ----- Error log 1708 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1709 1710 // ----- Return 1711 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1712 return PclZip::errorCode(); 1713 } 1714 1715 // ----- Get the value 1716 $v_work_list = array(); 1717 if (is_string($p_options_list[$i+1])) { 1718 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'"); 1719 1720 // ----- Remove spaces 1721 $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); 1722 1723 // ----- Parse items 1724 $v_work_list = explode(",", $p_options_list[$i+1]); 1725 } 1726 else if (is_integer($p_options_list[$i+1])) { 1727 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an integer '".$p_options_list[$i+1]."'"); 1728 $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; 1729 } 1730 else if (is_array($p_options_list[$i+1])) { 1731 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array"); 1732 $v_work_list = $p_options_list[$i+1]; 1733 } 1734 else { 1735 // ----- Error log 1736 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1737 1738 // ----- Return 1739 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1740 return PclZip::errorCode(); 1741 } 1742 1743 // ----- Reduce the index list 1744 // each index item in the list must be a couple with a start and 1745 // an end value : [0,3], [5-5], [8-10], ... 1746 // ----- Check the format of each item 1747 $v_sort_flag=false; 1748 $v_sort_value=0; 1749 for ($j=0; $j<sizeof($v_work_list); $j++) { 1750 // ----- Explode the item 1751 $v_item_list = explode("-", $v_work_list[$j]); 1752 $v_size_item_list = sizeof($v_item_list); 1753 1754 // ----- TBC : Here we might check that each item is a 1755 // real integer ... 1756 1757 // ----- Look for single value 1758 if ($v_size_item_list == 1) { 1759 // ----- Set the option value 1760 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; 1761 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; 1762 } 1763 elseif ($v_size_item_list == 2) { 1764 // ----- Set the option value 1765 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; 1766 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; 1767 } 1768 else { 1769 // ----- Error log 1770 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1771 1772 // ----- Return 1773 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1774 return PclZip::errorCode(); 1775 } 1776 1777 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extracted index item = [".$v_result_list[$p_options_list[$i]][$j]['start'].",".$v_result_list[$p_options_list[$i]][$j]['end']."]"); 1778 1779 // ----- Look for list sort 1780 if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { 1781 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The list should be sorted ..."); 1782 $v_sort_flag=true; 1783 1784 // ----- TBC : An automatic sort should be writen ... 1785 // ----- Error log 1786 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1787 1788 // ----- Return 1789 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1790 return PclZip::errorCode(); 1791 } 1792 $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; 1793 } 1794 1795 // ----- Sort the items 1796 if ($v_sort_flag) { 1797 // TBC : To Be Completed 1798 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ..."); 1799 } 1800 1801 // ----- Next option 1802 $i++; 1803 break; 1804 1805 // ----- Look for options that request no value 1806 case PCLZIP_OPT_REMOVE_ALL_PATH : 1807 case PCLZIP_OPT_EXTRACT_AS_STRING : 1808 case PCLZIP_OPT_NO_COMPRESSION : 1809 case PCLZIP_OPT_EXTRACT_IN_OUTPUT : 1810 case PCLZIP_OPT_REPLACE_NEWER : 1811 case PCLZIP_OPT_STOP_ON_ERROR : 1812 $v_result_list[$p_options_list[$i]] = true; 1813 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1814 break; 1815 1816 // ----- Look for options that request an octal value 1817 case PCLZIP_OPT_SET_CHMOD : 1818 // ----- Check the number of parameters 1819 if (($i+1) >= $p_size) { 1820 // ----- Error log 1821 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1822 1823 // ----- Return 1824 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1825 return PclZip::errorCode(); 1826 } 1827 1828 // ----- Get the value 1829 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1830 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1831 $i++; 1832 break; 1833 1834 // ----- Look for options that request a call-back 1835 case PCLZIP_CB_PRE_EXTRACT : 1836 case PCLZIP_CB_POST_EXTRACT : 1837 case PCLZIP_CB_PRE_ADD : 1838 case PCLZIP_CB_POST_ADD : 1839 /* for futur use 1840 case PCLZIP_CB_PRE_DELETE : 1841 case PCLZIP_CB_POST_DELETE : 1842 case PCLZIP_CB_PRE_LIST : 1843 case PCLZIP_CB_POST_LIST : 1844 */ 1845 // ----- Check the number of parameters 1846 if (($i+1) >= $p_size) { 1847 // ----- Error log 1848 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1849 1850 // ----- Return 1851 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1852 return PclZip::errorCode(); 1853 } 1854 1855 // ----- Get the value 1856 $v_function_name = $p_options_list[$i+1]; 1857 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "call-back ".PclZipUtilOptionText($p_options_list[$i])." = '".$v_function_name."'"); 1858 1859 // ----- Check that the value is a valid existing function 1860 if (!function_exists($v_function_name)) { 1861 // ----- Error log 1862 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1863 1864 // ----- Return 1865 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1866 return PclZip::errorCode(); 1867 } 1868 1869 // ----- Set the attribute 1870 $v_result_list[$p_options_list[$i]] = $v_function_name; 1871 $i++; 1872 break; 1873 1874 default : 1875 // ----- Error log 1876 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 1877 "Unknown parameter '" 1793 1878 .$p_options_list[$i]."'"); 1794 1879 1795 // ----- Return 1796 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1797 return PclZip::errorCode(); 1798 } 1799 1800 // ----- Next options 1801 $i++; 1802 } 1803 1804 // ----- Look for mandatory options 1805 if ($v_requested_options !== false) { 1806 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { 1807 // ----- Look for mandatory option 1808 if ($v_requested_options[$key] == 'mandatory') { 1809 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); 1810 // ----- Look if present 1811 if (!isset($v_result_list[$key])) { 1812 // ----- Error log 1813 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); 1814 1815 // ----- Return 1816 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1817 return PclZip::errorCode(); 1818 } 1819 } 1820 } 1821 } 1822 1823 // ----- Return 1824 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1825 return $v_result; 1880 // ----- Return 1881 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1882 return PclZip::errorCode(); 1883 } 1884 1885 // ----- Next options 1886 $i++; 1887 } 1888 1889 // ----- Look for mandatory options 1890 if ($v_requested_options !== false) { 1891 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { 1892 // ----- Look for mandatory option 1893 if ($v_requested_options[$key] == 'mandatory') { 1894 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); 1895 // ----- Look if present 1896 if (!isset($v_result_list[$key])) { 1897 // ----- Error log 1898 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); 1899 1900 // ----- Return 1901 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1902 return PclZip::errorCode(); 1903 } 1904 } 1905 } 1906 } 1907 1908 // ----- Look for default values 1909 if (!isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) { 1910 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Calculate auto threshold"); 1911 1912 } 1913 1914 // ----- Return 1915 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1916 return $v_result; 1917 } 1918 // -------------------------------------------------------------------------------- 1919 1920 // -------------------------------------------------------------------------------- 1921 // Function : privOptionDefaultThreshold() 1922 // Description : 1923 // Parameters : 1924 // Return Values : 1925 // -------------------------------------------------------------------------------- 1926 function privOptionDefaultThreshold(&$p_options) 1927 { 1928 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOptionDefaultThreshold", ""); 1929 $v_result=1; 1930 1931 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Create an auto-threshold for use of temporay files"); 1932 // ----- Get 'memory_limit' configuration value 1933 $v_memory_limit = ini_get('memory_limit'); 1934 $v_memory_limit = trim($v_memory_limit); 1935 $last = strtolower(substr($v_memory_limit, -1)); 1936 1937 if($last == 'g') 1938 //$v_memory_limit = $v_memory_limit*1024*1024*1024; 1939 $v_memory_limit = $v_memory_limit*1073741824; 1940 if($last == 'm') 1941 //$v_memory_limit = $v_memory_limit*1024*1024; 1942 $v_memory_limit = $v_memory_limit*1048576; 1943 if($last == 'k') 1944 $v_memory_limit = $v_memory_limit*1024; 1945 1946 $p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD] = floor($v_memory_limit/2); 1947 1948 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Threshold value is : ".$p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD]." bytes"); 1949 1950 // ----- Sanity check : No threshold if value lower than 1M 1951 if ($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD] < 1048576) { 1952 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Unset the threshold (value ".$p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD].") because under 1Mo sanity check)"); 1953 unset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD]); 1954 } 1955 1956 // ----- Return 1957 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1958 return $v_result; 1826 1959 } 1827 1960 // -------------------------------------------------------------------------------- … … 1837 1970 function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) 1838 1971 { 1839 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", ""); 1840 $v_result=1; 1841 1842 // ----- For each file in the list check the attributes 1843 foreach ($p_file_list as $v_key => $v_value) { 1844 1845 // ----- Check if the option is supported 1846 if (!isset($v_requested_options[$v_key])) { 1847 // ----- Error log 1848 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); 1849 1850 // ----- Return 1851 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1852 return PclZip::errorCode(); 1853 } 1854 1855 // ----- Look for attribute 1856 switch ($v_key) { 1857 case PCLZIP_ATT_FILE_NAME : 1858 if (!is_string($v_value)) { 1859 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1860 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1861 return PclZip::errorCode(); 1862 } 1863 1864 $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); 1865 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 1866 1867 if ($p_filedescr['filename'] == '') { 1868 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); 1869 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1870 return PclZip::errorCode(); 1871 } 1872 1873 break; 1874 1875 case PCLZIP_ATT_FILE_NEW_SHORT_NAME : 1876 if (!is_string($v_value)) { 1877 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1878 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1879 return PclZip::errorCode(); 1880 } 1881 1882 $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); 1883 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 1884 1885 if ($p_filedescr['new_short_name'] == '') { 1886 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); 1887 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1888 return PclZip::errorCode(); 1889 } 1890 break; 1891 1892 case PCLZIP_ATT_FILE_NEW_FULL_NAME : 1893 if (!is_string($v_value)) { 1894 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1895 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1896 return PclZip::errorCode(); 1897 } 1898 1899 $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); 1900 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 1901 1902 if ($p_filedescr['new_full_name'] == '') { 1903 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); 1904 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1905 return PclZip::errorCode(); 1906 } 1907 break; 1908 1909 default : 1910 // ----- Error log 1911 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 1912 "Unknown parameter '".$v_key."'"); 1913 1914 // ----- Return 1915 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1916 return PclZip::errorCode(); 1917 } 1918 1919 // ----- Look for mandatory options 1920 if ($v_requested_options !== false) { 1921 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { 1922 // ----- Look for mandatory option 1923 if ($v_requested_options[$key] == 'mandatory') { 1924 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); 1925 // ----- Look if present 1926 if (!isset($p_file_list[$key])) { 1927 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); 1928 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1929 return PclZip::errorCode(); 1930 } 1931 } 1932 } 1933 } 1934 1935 // end foreach 1936 } 1937 1938 // ----- Return 1939 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1940 return $v_result; 1972 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", ""); 1973 $v_result=1; 1974 1975 // ----- For each file in the list check the attributes 1976 foreach ($p_file_list as $v_key => $v_value) { 1977 1978 // ----- Check if the option is supported 1979 if (!isset($v_requested_options[$v_key])) { 1980 // ----- Error log 1981 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); 1982 1983 // ----- Return 1984 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1985 return PclZip::errorCode(); 1986 } 1987 1988 // ----- Look for attribute 1989 switch ($v_key) { 1990 case PCLZIP_ATT_FILE_NAME : 1991 if (!is_string($v_value)) { 1992 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1993 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1994 return PclZip::errorCode(); 1995 } 1996 1997 $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); 1998 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 1999 2000 if ($p_filedescr['filename'] == '') { 2001 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); 2002 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2003 return PclZip::errorCode(); 2004 } 2005 2006 break; 2007 2008 case PCLZIP_ATT_FILE_NEW_SHORT_NAME : 2009 if (!is_string($v_value)) { 2010 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 2011 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2012 return PclZip::errorCode(); 2013 } 2014 2015 $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); 2016 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 2017 2018 if ($p_filedescr['new_short_name'] == '') { 2019 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); 2020 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2021 return PclZip::errorCode(); 2022 } 2023 break; 2024 2025 case PCLZIP_ATT_FILE_NEW_FULL_NAME : 2026 if (!is_string($v_value)) { 2027 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 2028 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2029 return PclZip::errorCode(); 2030 } 2031 2032 $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); 2033 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 2034 2035 if ($p_filedescr['new_full_name'] == '') { 2036 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); 2037 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2038 return PclZip::errorCode(); 2039 } 2040 break; 2041 2042 // ----- Look for options that takes a string 2043 case PCLZIP_ATT_FILE_COMMENT : 2044 if (!is_string($v_value)) { 2045 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 2046 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2047 return PclZip::errorCode(); 2048 } 2049 2050 $p_filedescr['comment'] = $v_value; 2051 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 2052 break; 2053 2054 case PCLZIP_ATT_FILE_MTIME : 2055 if (!is_integer($v_value)) { 2056 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); 2057 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2058 return PclZip::errorCode(); 2059 } 2060 2061 $p_filedescr['mtime'] = $v_value; 2062 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 2063 break; 2064 2065 case PCLZIP_ATT_FILE_CONTENT : 2066 $p_filedescr['content'] = $v_value; 2067 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 2068 break; 2069 2070 default : 2071 // ----- Error log 2072 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 2073 "Unknown parameter '".$v_key."'"); 2074 2075 // ----- Return 2076 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2077 return PclZip::errorCode(); 2078 } 2079 2080 // ----- Look for mandatory options 2081 if ($v_requested_options !== false) { 2082 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { 2083 // ----- Look for mandatory option 2084 if ($v_requested_options[$key] == 'mandatory') { 2085 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); 2086 // ----- Look if present 2087 if (!isset($p_file_list[$key])) { 2088 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); 2089 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2090 return PclZip::errorCode(); 2091 } 2092 } 2093 } 2094 } 2095 2096 // end foreach 2097 } 2098 2099 // ----- Return 2100 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2101 return $v_result; 1941 2102 } 1942 2103 // -------------------------------------------------------------------------------- … … 1945 2106 // Function : privFileDescrExpand() 1946 2107 // Description : 2108 // This method look for each item of the list to see if its a file, a folder 2109 // or a string to be added as file. For any other type of files (link, other) 2110 // just ignore the item. 2111 // Then prepare the information that will be stored for that file. 2112 // When its a folder, expand the folder with all the files that are in that 2113 // folder (recursively). 1947 2114 // Parameters : 1948 2115 // Return Values : … … 1952 2119 function privFileDescrExpand(&$p_filedescr_list, &$p_options) 1953 2120 { 1954 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", ""); 1955 $v_result=1; 1956 1957 // ----- Create a result list 1958 $v_result_list = array(); 1959 1960 // ----- Look each entry 1961 for ($i=0; $i<sizeof($p_filedescr_list); $i++) { 1962 // ----- Get filedescr 1963 $v_descr = $p_filedescr_list[$i]; 1964 1965 // ----- Reduce the filename 1966 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'"); 1967 $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename']); 1968 $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); 1969 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'"); 1970 1971 // ----- Get type of descr 1972 if (!file_exists($v_descr['filename'])) { 1973 // ----- Error log 1974 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exists"); 1975 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exists"); 1976 1977 // ----- Return 1978 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1979 return PclZip::errorCode(); 1980 } 1981 if (@is_file($v_descr['filename'])) { 1982 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file"); 1983 $v_descr['type'] = 'file'; 1984 } 1985 else if (@is_dir($v_descr['filename'])) { 1986 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder"); 1987 $v_descr['type'] = 'folder'; 1988 } 1989 else if (@is_link($v_descr['filename'])) { 1990 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link"); 1991 // skip 1992 continue; 1993 } 1994 else { 1995 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type"); 1996 // skip 1997 continue; 1998 } 1999 2000 // ----- Calculate the stored filename 2001 $this->privCalculateStoredFilename($v_descr, $p_options); 2002 2003 // ----- Add the descriptor in result list 2004 $v_result_list[sizeof($v_result_list)] = $v_descr; 2005 2006 // ----- Look for folder 2007 if ($v_descr['type'] == 'folder') { 2008 // ----- List of items in folder 2009 $v_dirlist_descr = array(); 2010 $v_dirlist_nb = 0; 2011 if ($v_folder_handler = @opendir($v_descr['filename'])) { 2012 while (($v_item_handler = @readdir($v_folder_handler)) !== false) { 2013 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory"); 2014 2015 // ----- Skip '.' and '..' 2016 if (($v_item_handler == '.') || ($v_item_handler == '..')) { 2017 continue; 2018 } 2019 2020 // ----- Compose the full filename 2021 $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; 2022 2023 // ----- Look for different stored filename 2024 // Because the name of the folder was changed, the name of the 2025 // files/sub-folders also change 2026 if ($v_descr['stored_filename'] != $v_descr['filename']) { 2027 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; 2028 } 2029 2030 $v_dirlist_nb++; 2031 } 2032 } 2033 else { 2034 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped."); 2035 // TBC : unable to open folder in read mode 2036 } 2037 2038 // ----- Expand each element of the list 2039 if ($v_dirlist_nb != 0) { 2040 // ----- Expand 2041 if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { 2042 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2043 return $v_result; 2044 } 2045 2046 // ----- Concat the resulting list 2047 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')"); 2048 $v_result_list = array_merge($v_result_list, $v_dirlist_descr); 2049 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'"); 2050 } 2051 else { 2052 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand."); 2053 } 2054 2055 // ----- Free local array 2056 unset($v_dirlist_descr); 2057 } 2058 } 2059 2060 // ----- Get the result list 2061 $p_filedescr_list = $v_result_list; 2062 2063 // ----- Return 2064 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2065 return $v_result; 2121 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", ""); 2122 $v_result=1; 2123 2124 // ----- Create a result list 2125 $v_result_list = array(); 2126 2127 // ----- Look each entry 2128 for ($i=0; $i<sizeof($p_filedescr_list); $i++) { 2129 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for file ".$i."."); 2130 2131 // ----- Get filedescr 2132 $v_descr = $p_filedescr_list[$i]; 2133 2134 // ----- Reduce the filename 2135 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'"); 2136 $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); 2137 $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); 2138 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'"); 2139 2140 // ----- Look for real file or folder 2141 if (file_exists($v_descr['filename'])) { 2142 if (@is_file($v_descr['filename'])) { 2143 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file"); 2144 $v_descr['type'] = 'file'; 2145 } 2146 else if (@is_dir($v_descr['filename'])) { 2147 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder"); 2148 $v_descr['type'] = 'folder'; 2149 } 2150 else if (@is_link($v_descr['filename'])) { 2151 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link"); 2152 // skip 2153 continue; 2154 } 2155 else { 2156 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type"); 2157 // skip 2158 continue; 2159 } 2160 } 2161 2162 // ----- Look for string added as file 2163 else if (isset($v_descr['content'])) { 2164 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a string added as a file"); 2165 $v_descr['type'] = 'virtual_file'; 2166 } 2167 2168 // ----- Missing file 2169 else { 2170 // ----- Error log 2171 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exist"); 2172 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist"); 2173 2174 // ----- Return 2175 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2176 return PclZip::errorCode(); 2177 } 2178 2179 // ----- Calculate the stored filename 2180 $this->privCalculateStoredFilename($v_descr, $p_options); 2181 2182 // ----- Add the descriptor in result list 2183 $v_result_list[sizeof($v_result_list)] = $v_descr; 2184 2185 // ----- Look for folder 2186 if ($v_descr['type'] == 'folder') { 2187 // ----- List of items in folder 2188 $v_dirlist_descr = array(); 2189 $v_dirlist_nb = 0; 2190 if ($v_folder_handler = @opendir($v_descr['filename'])) { 2191 while (($v_item_handler = @readdir($v_folder_handler)) !== false) { 2192 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory"); 2193 2194 // ----- Skip '.' and '..' 2195 if (($v_item_handler == '.') || ($v_item_handler == '..')) { 2196 continue; 2197 } 2198 2199 // ----- Compose the full filename 2200 $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; 2201 2202 // ----- Look for different stored filename 2203 // Because the name of the folder was changed, the name of the 2204 // files/sub-folders also change 2205 if ($v_descr['stored_filename'] != $v_descr['filename']) { 2206 if ($v_descr['stored_filename'] != '') { 2207 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; 2208 } 2209 else { 2210 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; 2211 } 2212 } 2213 2214 $v_dirlist_nb++; 2215 } 2216 2217 @closedir($v_folder_handler); 2218 } 2219 else { 2220 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped."); 2221 // TBC : unable to open folder in read mode 2222 } 2223 2224 // ----- Expand each element of the list 2225 if ($v_dirlist_nb != 0) { 2226 // ----- Expand 2227 if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { 2228 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2229 return $v_result; 2230 } 2231 2232 // ----- Concat the resulting list 2233 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')"); 2234 $v_result_list = array_merge($v_result_list, $v_dirlist_descr); 2235 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'"); 2236 } 2237 else { 2238 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand."); 2239 } 2240 2241 // ----- Free local array 2242 unset($v_dirlist_descr); 2243 } 2244 } 2245 2246 // ----- Get the result list 2247 $p_filedescr_list = $v_result_list; 2248 2249 // ----- Return 2250 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2251 return $v_result; 2066 2252 } 2067 2253 // -------------------------------------------------------------------------------- … … 2075 2261 function privCreate($p_filedescr_list, &$p_result_list, &$p_options) 2076 2262 { 2077 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list");2078 $v_result=1;2079 $v_list_detail = array();2080 2081 // ----- Magic quotes trick2082 $this->privDisableMagicQuotes();2083 2084 // ----- Open the file in write mode2085 if (($v_result = $this->privOpenFd('wb')) != 1)2086 {2087 // ----- Return2088 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2089 return $v_result;2090 }2091 2092 // ----- Add the list of files2093 $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);2094 2095 // ----- Close2096 $this->privCloseFd();2097 2098 // ----- Magic quotes trick2099 $this->privSwapBackMagicQuotes();2100 2101 // ----- Return2102 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2103 return $v_result;2263 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list"); 2264 $v_result=1; 2265 $v_list_detail = array(); 2266 2267 // ----- Magic quotes trick 2268 $this->privDisableMagicQuotes(); 2269 2270 // ----- Open the file in write mode 2271 if (($v_result = $this->privOpenFd('wb')) != 1) 2272 { 2273 // ----- Return 2274 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2275 return $v_result; 2276 } 2277 2278 // ----- Add the list of files 2279 $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options); 2280 2281 // ----- Close 2282 $this->privCloseFd(); 2283 2284 // ----- Magic quotes trick 2285 $this->privSwapBackMagicQuotes(); 2286 2287 // ----- Return 2288 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2289 return $v_result; 2104 2290 } 2105 2291 // -------------------------------------------------------------------------------- … … 2113 2299 function privAdd($p_filedescr_list, &$p_result_list, &$p_options) 2114 2300 { 2115 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list");2116 $v_result=1;2117 $v_list_detail = array();2118 2119 // ----- Look if the archive exists or is empty2120 if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))2121 {2122 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it.");2123 2124 // ----- Do a create2125 $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);2126 2127 // ----- Return2128 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2129 return $v_result;2130 }2131 // ----- Magic quotes trick2132 $this->privDisableMagicQuotes();2133 2134 // ----- Open the zip file2135 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");2136 if (($v_result=$this->privOpenFd('rb')) != 1)2137 {2138 // ----- Magic quotes trick2139 $this->privSwapBackMagicQuotes();2140 2141 // ----- Return2142 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2143 return $v_result;2144 }2145 2146 // ----- Read the central directory informations2147 $v_central_dir = array();2148 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)2149 {2150 $this->privCloseFd();2151 $this->privSwapBackMagicQuotes();2152 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2153 return $v_result;2154 }2155 2156 // ----- Go to beginning of File2157 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");2158 @rewind($this->zip_fd);2159 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");2160 2161 // ----- Creates a temporay file2162 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';2163 2164 // ----- Open the temporary file in write mode2165 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");2166 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)2167 {2168 $this->privCloseFd();2169 $this->privSwapBackMagicQuotes();2170 2171 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');2172 2173 // ----- Return2174 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());2175 return PclZip::errorCode();2176 }2177 2178 // ----- Copy the files from the archive to the temporary file2179 // TBC : Here I should better append the file and go back to erase the central dir2180 $v_size = $v_central_dir['offset'];2181 while ($v_size != 0)2182 {2183 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);2184 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");2185 $v_buffer = fread($this->zip_fd, $v_read_size);2186 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);2187 $v_size -= $v_read_size;2188 }2189 2190 // ----- Swap the file descriptor2191 // Here is a trick : I swap the temporary fd with the zip fd, in order to use2192 // the following methods on the temporary fil and not the real archive2193 $v_swap = $this->zip_fd;2194 $this->zip_fd = $v_zip_temp_fd;2195 $v_zip_temp_fd = $v_swap;2196 2197 // ----- Add the files2198 $v_header_list = array();2199 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)2200 {2201 fclose($v_zip_temp_fd);2202 $this->privCloseFd();2203 @unlink($v_zip_temp_name);2204 $this->privSwapBackMagicQuotes();2205 2206 // ----- Return2207 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2208 return $v_result;2209 }2210 2211 // ----- Store the offset of the central dir2212 $v_offset = @ftell($this->zip_fd);2213 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset");2214 2215 // ----- Copy the block of file headers from the old archive2216 $v_size = $v_central_dir['size'];2217 while ($v_size != 0)2218 {2219 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);2220 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");2221 $v_buffer = @fread($v_zip_temp_fd, $v_read_size);2222 @fwrite($this->zip_fd, $v_buffer, $v_read_size);2223 $v_size -= $v_read_size;2224 }2225 2226 // ----- Create the Central Dir files header2227 for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)2228 {2229 // ----- Create the file header2230 if ($v_header_list[$i]['status'] == 'ok') {2231 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {2232 fclose($v_zip_temp_fd);2233 $this->privCloseFd();2234 @unlink($v_zip_temp_name);2235 $this->privSwapBackMagicQuotes();2236 2237 // ----- Return2238 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2239 return $v_result;2240 }2241 $v_count++;2242 }2243 2244 // ----- Transform the header to a 'usable' info2245 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);2246 }2247 2248 // ----- Zip file comment2249 $v_comment = $v_central_dir['comment'];2250 if (isset($p_options[PCLZIP_OPT_COMMENT])) {2251 $v_comment = $p_options[PCLZIP_OPT_COMMENT];2252 }2253 if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {2254 $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];2255 }2256 if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {2257 $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;2258 }2259 2260 // ----- Calculate the size of the central header2261 $v_size = @ftell($this->zip_fd)-$v_offset;2262 2263 // ----- Create the central dir footer2264 if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)2265 {2266 // ----- Reset the file list2267 unset($v_header_list);2268 $this->privSwapBackMagicQuotes();2269 2270 // ----- Return2271 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2272 return $v_result;2273 }2274 2275 // ----- Swap back the file descriptor2276 $v_swap = $this->zip_fd;2277 $this->zip_fd = $v_zip_temp_fd;2278 $v_zip_temp_fd = $v_swap;2279 2280 // ----- Close2281 $this->privCloseFd();2282 2283 // ----- Close the temporary file2284 @fclose($v_zip_temp_fd);2285 2286 // ----- Magic quotes trick2287 $this->privSwapBackMagicQuotes();2288 2289 // ----- Delete the zip file2290 // TBC : I should test the result ...2291 @unlink($this->zipname);2292 2293 // ----- Rename the temporary file2294 // TBC : I should test the result ...2295 //@rename($v_zip_temp_name, $this->zipname);2296 PclZipUtilRename($v_zip_temp_name, $this->zipname);2297 2298 // ----- Return2299 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2300 return $v_result;2301 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list"); 2302 $v_result=1; 2303 $v_list_detail = array(); 2304 2305 // ----- Look if the archive exists or is empty 2306 if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) 2307 { 2308 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it."); 2309 2310 // ----- Do a create 2311 $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); 2312 2313 // ----- Return 2314 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2315 return $v_result; 2316 } 2317 // ----- Magic quotes trick 2318 $this->privDisableMagicQuotes(); 2319 2320 // ----- Open the zip file 2321 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 2322 if (($v_result=$this->privOpenFd('rb')) != 1) 2323 { 2324 // ----- Magic quotes trick 2325 $this->privSwapBackMagicQuotes(); 2326 2327 // ----- Return 2328 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2329 return $v_result; 2330 } 2331 2332 // ----- Read the central directory informations 2333 $v_central_dir = array(); 2334 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 2335 { 2336 $this->privCloseFd(); 2337 $this->privSwapBackMagicQuotes(); 2338 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2339 return $v_result; 2340 } 2341 2342 // ----- Go to beginning of File 2343 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); 2344 @rewind($this->zip_fd); 2345 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); 2346 2347 // ----- Creates a temporay file 2348 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; 2349 2350 // ----- Open the temporary file in write mode 2351 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 2352 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) 2353 { 2354 $this->privCloseFd(); 2355 $this->privSwapBackMagicQuotes(); 2356 2357 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); 2358 2359 // ----- Return 2360 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2361 return PclZip::errorCode(); 2362 } 2363 2364 // ----- Copy the files from the archive to the temporary file 2365 // TBC : Here I should better append the file and go back to erase the central dir 2366 $v_size = $v_central_dir['offset']; 2367 while ($v_size != 0) 2368 { 2369 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 2370 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 2371 $v_buffer = fread($this->zip_fd, $v_read_size); 2372 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 2373 $v_size -= $v_read_size; 2374 } 2375 2376 // ----- Swap the file descriptor 2377 // Here is a trick : I swap the temporary fd with the zip fd, in order to use 2378 // the following methods on the temporary fil and not the real archive 2379 $v_swap = $this->zip_fd; 2380 $this->zip_fd = $v_zip_temp_fd; 2381 $v_zip_temp_fd = $v_swap; 2382 2383 // ----- Add the files 2384 $v_header_list = array(); 2385 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) 2386 { 2387 fclose($v_zip_temp_fd); 2388 $this->privCloseFd(); 2389 @unlink($v_zip_temp_name); 2390 $this->privSwapBackMagicQuotes(); 2391 2392 // ----- Return 2393 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2394 return $v_result; 2395 } 2396 2397 // ----- Store the offset of the central dir 2398 $v_offset = @ftell($this->zip_fd); 2399 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset"); 2400 2401 // ----- Copy the block of file headers from the old archive 2402 $v_size = $v_central_dir['size']; 2403 while ($v_size != 0) 2404 { 2405 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 2406 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 2407 $v_buffer = @fread($v_zip_temp_fd, $v_read_size); 2408 @fwrite($this->zip_fd, $v_buffer, $v_read_size); 2409 $v_size -= $v_read_size; 2410 } 2411 2412 // ----- Create the Central Dir files header 2413 for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++) 2414 { 2415 // ----- Create the file header 2416 if ($v_header_list[$i]['status'] == 'ok') { 2417 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { 2418 fclose($v_zip_temp_fd); 2419 $this->privCloseFd(); 2420 @unlink($v_zip_temp_name); 2421 $this->privSwapBackMagicQuotes(); 2422 2423 // ----- Return 2424 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2425 return $v_result; 2426 } 2427 $v_count++; 2428 } 2429 2430 // ----- Transform the header to a 'usable' info 2431 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); 2432 } 2433 2434 // ----- Zip file comment 2435 $v_comment = $v_central_dir['comment']; 2436 if (isset($p_options[PCLZIP_OPT_COMMENT])) { 2437 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; 2438 } 2439 if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) { 2440 $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT]; 2441 } 2442 if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) { 2443 $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment; 2444 } 2445 2446 // ----- Calculate the size of the central header 2447 $v_size = @ftell($this->zip_fd)-$v_offset; 2448 2449 // ----- Create the central dir footer 2450 if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) 2451 { 2452 // ----- Reset the file list 2453 unset($v_header_list); 2454 $this->privSwapBackMagicQuotes(); 2455 2456 // ----- Return 2457 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2458 return $v_result; 2459 } 2460 2461 // ----- Swap back the file descriptor 2462 $v_swap = $this->zip_fd; 2463 $this->zip_fd = $v_zip_temp_fd; 2464 $v_zip_temp_fd = $v_swap; 2465 2466 // ----- Close 2467 $this->privCloseFd(); 2468 2469 // ----- Close the temporary file 2470 @fclose($v_zip_temp_fd); 2471 2472 // ----- Magic quotes trick 2473 $this->privSwapBackMagicQuotes(); 2474 2475 // ----- Delete the zip file 2476 // TBC : I should test the result ... 2477 @unlink($this->zipname); 2478 2479 // ----- Rename the temporary file 2480 // TBC : I should test the result ... 2481 //@rename($v_zip_temp_name, $this->zipname); 2482 PclZipUtilRename($v_zip_temp_name, $this->zipname); 2483 2484 // ----- Return 2485 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2486 return $v_result; 2301 2487 } 2302 2488 // -------------------------------------------------------------------------------- … … 2309 2495 function privOpenFd($p_mode) 2310 2496 { 2311 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOpenFd", 'mode='.$p_mode);2312 $v_result=1;2313 2314 // ----- Look if already open2315 if ($this->zip_fd != 0)2316 {2317 // ----- Error log2318 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');2319 2320 // ----- Return2321 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());2322 return PclZip::errorCode();2323 }2324 2325 // ----- Open the zip file2326 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Open file in '.$p_mode.' mode');2327 if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)2328 {2329 // ----- Error log2330 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');2331 2332 // ----- Return2333 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());2334 return PclZip::errorCode();2335 }2336 2337 // ----- Return2338 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2339 return $v_result;2497 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOpenFd", 'mode='.$p_mode); 2498 $v_result=1; 2499 2500 // ----- Look if already open 2501 if ($this->zip_fd != 0) 2502 { 2503 // ----- Error log 2504 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); 2505 2506 // ----- Return 2507 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2508 return PclZip::errorCode(); 2509 } 2510 2511 // ----- Open the zip file 2512 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Open file in '.$p_mode.' mode'); 2513 if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) 2514 { 2515 // ----- Error log 2516 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); 2517 2518 // ----- Return 2519 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2520 return PclZip::errorCode(); 2521 } 2522 2523 // ----- Return 2524 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2525 return $v_result; 2340 2526 } 2341 2527 // -------------------------------------------------------------------------------- … … 2348 2534 function privCloseFd() 2349 2535 { 2350 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCloseFd", "");2351 $v_result=1;2352 2353 if ($this->zip_fd != 0)2354 @fclose($this->zip_fd);2355 $this->zip_fd = 0;2356 2357 // ----- Return2358 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2359 return $v_result;2536 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCloseFd", ""); 2537 $v_result=1; 2538 2539 if ($this->zip_fd != 0) 2540 @fclose($this->zip_fd); 2541 $this->zip_fd = 0; 2542 2543 // ----- Return 2544 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2545 return $v_result; 2360 2546 } 2361 2547 // -------------------------------------------------------------------------------- … … 2377 2563 function privAddList($p_filedescr_list, &$p_result_list, &$p_options) 2378 2564 { 2379 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list");2380 $v_result=1;2381 2382 // ----- Add the files2383 $v_header_list = array();2384 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)2385 {2386 // ----- Return2387 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2388 return $v_result;2389 }2390 2391 // ----- Store the offset of the central dir2392 $v_offset = @ftell($this->zip_fd);2393 2394 // ----- Create the Central Dir files header2395 for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)2396 {2397 // ----- Create the file header2398 if ($v_header_list[$i]['status'] == 'ok') {2399 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {2400 // ----- Return2401 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2402 return $v_result;2403 }2404 $v_count++;2405 }2406 2407 // ----- Transform the header to a 'usable' info2408 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);2409 }2410 2411 // ----- Zip file comment2412 $v_comment = '';2413 if (isset($p_options[PCLZIP_OPT_COMMENT])) {2414 $v_comment = $p_options[PCLZIP_OPT_COMMENT];2415 }2416 2417 // ----- Calculate the size of the central header2418 $v_size = @ftell($this->zip_fd)-$v_offset;2419 2420 // ----- Create the central dir footer2421 if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)2422 {2423 // ----- Reset the file list2424 unset($v_header_list);2425 2426 // ----- Return2427 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2428 return $v_result;2429 }2430 2431 // ----- Return2432 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2433 return $v_result;2565 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list"); 2566 $v_result=1; 2567 2568 // ----- Add the files 2569 $v_header_list = array(); 2570 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) 2571 { 2572 // ----- Return 2573 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2574 return $v_result; 2575 } 2576 2577 // ----- Store the offset of the central dir 2578 $v_offset = @ftell($this->zip_fd); 2579 2580 // ----- Create the Central Dir files header 2581 for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++) 2582 { 2583 // ----- Create the file header 2584 if ($v_header_list[$i]['status'] == 'ok') { 2585 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { 2586 // ----- Return 2587 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2588 return $v_result; 2589 } 2590 $v_count++; 2591 } 2592 2593 // ----- Transform the header to a 'usable' info 2594 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); 2595 } 2596 2597 // ----- Zip file comment 2598 $v_comment = ''; 2599 if (isset($p_options[PCLZIP_OPT_COMMENT])) { 2600 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; 2601 } 2602 2603 // ----- Calculate the size of the central header 2604 $v_size = @ftell($this->zip_fd)-$v_offset; 2605 2606 // ----- Create the central dir footer 2607 if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) 2608 { 2609 // ----- Reset the file list 2610 unset($v_header_list); 2611 2612 // ----- Return 2613 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2614 return $v_result; 2615 } 2616 2617 // ----- Return 2618 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2619 return $v_result; 2434 2620 } 2435 2621 // -------------------------------------------------------------------------------- … … 2439 2625 // Description : 2440 2626 // Parameters : 2441 // $p_filedescr_list : An array containing the file description 2442 // or directory names to add in the zip2627 // $p_filedescr_list : An array containing the file description 2628 // or directory names to add in the zip 2443 2629 // $p_result_list : list of added files with their properties (specially the status field) 2444 2630 // Return Values : … … 2446 2632 function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) 2447 2633 { 2448 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "filedescr_list"); 2449 $v_result=1; 2450 $v_header = array(); 2451 2452 // ----- Recuperate the current number of elt in list 2453 $v_nb = sizeof($p_result_list); 2454 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Before add, list have ".$v_nb." elements"); 2455 2456 // ----- Loop on the files 2457 for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { 2458 // ----- Format the filename 2459 $p_filedescr_list[$j]['filename'] 2460 = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); 2461 2462 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'"); 2463 2464 // ----- Skip empty file names 2465 // TBC : Can this be possible ? not checked in DescrParseAtt ? 2466 if ($p_filedescr_list[$j]['filename'] == "") { 2467 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Skip empty filename"); 2468 continue; 2469 } 2470 2471 // ----- Check the filename 2472 if (!file_exists($p_filedescr_list[$j]['filename'])) { 2473 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_filedescr_list[$j]['filename']."' does not exists"); 2474 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exists"); 2475 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2476 return PclZip::errorCode(); 2477 } 2478 2479 // ----- Look if it is a file or a dir with no all path remove option 2480 if ( (is_file($p_filedescr_list[$j]['filename'])) 2481 || ( is_dir($p_filedescr_list[$j]['filename']) 2482 && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) 2483 || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { 2484 2485 // ----- Add the file 2486 $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header, 2487 $p_options); 2488 if ($v_result != 1) { 2489 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2490 return $v_result; 2491 } 2492 2493 // ----- Store the file infos 2494 $p_result_list[$v_nb++] = $v_header; 2495 } 2496 } 2497 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "After add, list have ".$v_nb." elements"); 2498 2499 // ----- Return 2500 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2501 return $v_result; 2634 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "filedescr_list"); 2635 $v_result=1; 2636 $v_header = array(); 2637 2638 // ----- Recuperate the current number of elt in list 2639 $v_nb = sizeof($p_result_list); 2640 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Before add, list have ".$v_nb." elements"); 2641 2642 // ----- Loop on the files 2643 for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { 2644 // ----- Format the filename 2645 $p_filedescr_list[$j]['filename'] 2646 = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); 2647 2648 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'"); 2649 2650 // ----- Skip empty file names 2651 // TBC : Can this be possible ? not checked in DescrParseAtt ? 2652 if ($p_filedescr_list[$j]['filename'] == "") { 2653 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Skip empty filename"); 2654 continue; 2655 } 2656 2657 // ----- Check the filename 2658 if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') 2659 && (!file_exists($p_filedescr_list[$j]['filename']))) { 2660 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); 2661 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); 2662 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2663 return PclZip::errorCode(); 2664 } 2665 2666 // ----- Look if it is a file or a dir with no all path remove option 2667 // or a dir with all its path removed 2668 // if ( (is_file($p_filedescr_list[$j]['filename'])) 2669 // || ( is_dir($p_filedescr_list[$j]['filename']) 2670 if ( ($p_filedescr_list[$j]['type'] == 'file') 2671 || ($p_filedescr_list[$j]['type'] == 'virtual_file') 2672 || ( ($p_filedescr_list[$j]['type'] == 'folder') 2673 && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) 2674 || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) 2675 ) { 2676 2677 // ----- Add the file 2678 $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header, 2679 $p_options); 2680 if ($v_result != 1) { 2681 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2682 return $v_result; 2683 } 2684 2685 // ----- Store the file infos 2686 $p_result_list[$v_nb++] = $v_header; 2687 } 2688 } 2689 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "After add, list have ".$v_nb." elements"); 2690 2691 // ----- Return 2692 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2693 return $v_result; 2502 2694 } 2503 2695 // -------------------------------------------------------------------------------- … … 2511 2703 function privAddFile($p_filedescr, &$p_header, &$p_options) 2512 2704 { 2513 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'"); 2514 $v_result=1; 2515 2516 // ----- Working variable 2517 $p_filename = $p_filedescr['filename']; 2518 2519 // TBC : Already done in the fileAtt check ... ? 2520 if ($p_filename == "") { 2521 // ----- Error log 2522 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); 2523 2524 // ----- Return 2525 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2526 return PclZip::errorCode(); 2527 } 2528 2529 // ----- Look for a stored different filename 2530 if (isset($p_filedescr['stored_filename'])) { 2531 $v_stored_filename = $p_filedescr['stored_filename']; 2532 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is NOT the same "'.$v_stored_filename.'"'); 2533 } 2534 else { 2535 $v_stored_filename = $p_filedescr['stored_filename']; 2536 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is the same'); 2537 } 2538 2539 // ----- Set the file properties 2540 clearstatcache(); 2541 $p_header['version'] = 20; 2542 $p_header['version_extracted'] = 10; 2543 $p_header['flag'] = 0; 2544 $p_header['compression'] = 0; 2545 $p_header['mtime'] = filemtime($p_filename); 2546 $p_header['crc'] = 0; 2547 $p_header['compressed_size'] = 0; 2548 $p_header['size'] = filesize($p_filename); 2549 $p_header['filename_len'] = strlen($p_filename); 2550 $p_header['extra_len'] = 0; 2551 $p_header['comment_len'] = 0; 2552 $p_header['disk'] = 0; 2553 $p_header['internal'] = 0; 2554 // $p_header['external'] = (is_file($p_filename)?0xFE49FFE0:0x41FF0010); 2555 $p_header['external'] = (is_file($p_filename)?0x00000000:0x00000010); 2556 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header external extension '".sprintf("0x%X",$p_header['external'])."'"); 2557 $p_header['offset'] = 0; 2558 $p_header['filename'] = $p_filename; 2559 $p_header['stored_filename'] = $v_stored_filename; 2560 $p_header['extra'] = ''; 2561 $p_header['comment'] = ''; 2562 $p_header['status'] = 'ok'; 2563 $p_header['index'] = -1; 2564 2565 // ----- Look for pre-add callback 2566 if (isset($p_options[PCLZIP_CB_PRE_ADD])) { 2567 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_ADD]."()') is defined for the extraction"); 2568 2569 // ----- Generate a local information 2570 $v_local_header = array(); 2571 $this->privConvertHeader2FileInfo($p_header, $v_local_header); 2572 2573 // ----- Call the callback 2574 // Here I do not use call_user_func() because I need to send a reference to the 2575 // header. 2576 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);'); 2577 if ($v_result == 0) { 2578 // ----- Change the file status 2579 $p_header['status'] = "skipped"; 2580 $v_result = 1; 2581 } 2582 2583 // ----- Update the informations 2584 // Only some fields can be modified 2585 if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { 2586 $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); 2587 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New stored filename is '".$p_header['stored_filename']."'"); 2588 } 2589 } 2590 2591 // ----- Look for empty stored filename 2592 if ($p_header['stored_filename'] == "") { 2593 $p_header['status'] = "filtered"; 2594 } 2595 2596 // ----- Check the path length 2597 if (strlen($p_header['stored_filename']) > 0xFF) { 2598 $p_header['status'] = 'filename_too_long'; 2599 } 2600 2601 // ----- Look if no error, or file not skipped 2602 if ($p_header['status'] == 'ok') { 2603 2604 // ----- Look for a file 2605 if (is_file($p_filename)) 2606 { 2607 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file"); 2608 // ----- Open the source file 2609 if (($v_file = @fopen($p_filename, "rb")) == 0) { 2610 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); 2611 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2612 return PclZip::errorCode(); 2613 } 2614 2615 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { 2616 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed"); 2617 // ----- Read the file content 2618 $v_content_compressed = @fread($v_file, $p_header['size']); 2619 2620 // ----- Calculate the CRC 2621 $p_header['crc'] = @crc32($v_content_compressed); 2622 2623 // ----- Set header parameters 2624 $p_header['compressed_size'] = $p_header['size']; 2625 $p_header['compression'] = 0; 2626 } 2627 else { 2628 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed"); 2629 // ----- Read the file content 2630 $v_content = @fread($v_file, $p_header['size']); 2631 2632 // ----- Calculate the CRC 2633 $p_header['crc'] = @crc32($v_content); 2634 2635 // ----- Compress the file 2636 $v_content_compressed = @gzdeflate($v_content); 2637 2638 // ----- Set header parameters 2639 $p_header['compressed_size'] = strlen($v_content_compressed); 2640 $p_header['compression'] = 8; 2641 } 2642 2643 // ----- Look for encryption 2644 /* 2645 if ((isset($p_options[PCLZIP_OPT_CRYPT])) 2646 && ($p_options[PCLZIP_OPT_CRYPT] != "")) { 2647 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ...."); 2648 2649 // Should be a random header 2650 $v_header = 'xxxxxxxxxxxx'; 2651 $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed, 2652 $p_header['compressed_size'], 2653 $v_header, 2705 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'"); 2706 $v_result=1; 2707 2708 // ----- Working variable 2709 $p_filename = $p_filedescr['filename']; 2710 2711 // TBC : Already done in the fileAtt check ... ? 2712 if ($p_filename == "") { 2713 // ----- Error log 2714 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); 2715 2716 // ----- Return 2717 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2718 return PclZip::errorCode(); 2719 } 2720 2721 // ----- Look for a stored different filename 2722 /* TBC : Removed 2723 if (isset($p_filedescr['stored_filename'])) { 2724 $v_stored_filename = $p_filedescr['stored_filename']; 2725 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is NOT the same "'.$v_stored_filename.'"'); 2726 } 2727 else { 2728 $v_stored_filename = $p_filedescr['stored_filename']; 2729 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is the same'); 2730 } 2731 */ 2732 2733 // ----- Set the file properties 2734 clearstatcache(); 2735 $p_header['version'] = 20; 2736 $p_header['version_extracted'] = 10; 2737 $p_header['flag'] = 0; 2738 $p_header['compression'] = 0; 2739 $p_header['crc'] = 0; 2740 $p_header['compressed_size'] = 0; 2741 $p_header['filename_len'] = strlen($p_filename); 2742 $p_header['extra_len'] = 0; 2743 $p_header['disk'] = 0; 2744 $p_header['internal'] = 0; 2745 $p_header['offset'] = 0; 2746 $p_header['filename'] = $p_filename; 2747 // TBC : Removed $p_header['stored_filename'] = $v_stored_filename; 2748 $p_header['stored_filename'] = $p_filedescr['stored_filename']; 2749 $p_header['extra'] = ''; 2750 $p_header['status'] = 'ok'; 2751 $p_header['index'] = -1; 2752 2753 // ----- Look for regular file 2754 if ($p_filedescr['type']=='file') { 2755 $p_header['external'] = 0x00000000; 2756 $p_header['size'] = filesize($p_filename); 2757 } 2758 2759 // ----- Look for regular folder 2760 else if ($p_filedescr['type']=='folder') { 2761 $p_header['external'] = 0x00000010; 2762 $p_header['mtime'] = filemtime($p_filename); 2763 $p_header['size'] = filesize($p_filename); 2764 } 2765 2766 // ----- Look for virtual file 2767 else if ($p_filedescr['type'] == 'virtual_file') { 2768 $p_header['external'] = 0x00000000; 2769 $p_header['size'] = strlen($p_filedescr['content']); 2770 } 2771 2772 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header external extension '".sprintf("0x%X",$p_header['external'])."'"); 2773 2774 // ----- Look for filetime 2775 if (isset($p_filedescr['mtime'])) { 2776 $p_header['mtime'] = $p_filedescr['mtime']; 2777 } 2778 else if ($p_filedescr['type'] == 'virtual_file') { 2779 $p_header['mtime'] = time(); 2780 } 2781 else { 2782 $p_header['mtime'] = filemtime($p_filename); 2783 } 2784 2785 // ------ Look for file comment 2786 if (isset($p_filedescr['comment'])) { 2787 $p_header['comment_len'] = strlen($p_filedescr['comment']); 2788 $p_header['comment'] = $p_filedescr['comment']; 2789 } 2790 else { 2791 $p_header['comment_len'] = 0; 2792 $p_header['comment'] = ''; 2793 } 2794 2795 // ----- Look for pre-add callback 2796 if (isset($p_options[PCLZIP_CB_PRE_ADD])) { 2797 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_ADD]."()') is defined for the extraction"); 2798 2799 // ----- Generate a local information 2800 $v_local_header = array(); 2801 $this->privConvertHeader2FileInfo($p_header, $v_local_header); 2802 2803 // ----- Call the callback 2804 // Here I do not use call_user_func() because I need to send a reference to the 2805 // header. 2806 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);'); 2807 if ($v_result == 0) { 2808 // ----- Change the file status 2809 $p_header['status'] = "skipped"; 2810 $v_result = 1; 2811 } 2812 2813 // ----- Update the informations 2814 // Only some fields can be modified 2815 if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { 2816 $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); 2817 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New stored filename is '".$p_header['stored_filename']."'"); 2818 } 2819 } 2820 2821 // ----- Look for empty stored filename 2822 if ($p_header['stored_filename'] == "") { 2823 $p_header['status'] = "filtered"; 2824 } 2825 2826 // ----- Check the path length 2827 if (strlen($p_header['stored_filename']) > 0xFF) { 2828 $p_header['status'] = 'filename_too_long'; 2829 } 2830 2831 // ----- Look if no error, or file not skipped 2832 if ($p_header['status'] == 'ok') { 2833 2834 // ----- Look for a file 2835 if ($p_filedescr['type'] == 'file') { 2836 // ----- Look for using temporary file to zip 2837 if ( (!isset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_OFF])) 2838 && (isset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_ON]) 2839 || (isset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD]) 2840 && ($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { 2841 $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); 2842 if ($v_result >= PCLZIP_ERR_NO_ERROR) { 2843 return $v_result; 2844 } 2845 } 2846 2847 // ----- Use "in memory" zip algo 2848 else { 2849 2850 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file"); 2851 2852 // ----- Open the source file 2853 if (($v_file = @fopen($p_filename, "rb")) == 0) { 2854 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); 2855 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2856 return PclZip::errorCode(); 2857 } 2858 2859 // ----- Read the file content 2860 $v_content = @fread($v_file, $p_header['size']); 2861 2862 // ----- Close the file 2863 @fclose($v_file); 2864 2865 // ----- Calculate the CRC 2866 $p_header['crc'] = @crc32($v_content); 2867 2868 // ----- Look for no compression 2869 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { 2870 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed"); 2871 // ----- Set header parameters 2872 $p_header['compressed_size'] = $p_header['size']; 2873 $p_header['compression'] = 0; 2874 } 2875 2876 // ----- Look for normal compression 2877 else { 2878 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed"); 2879 // ----- Compress the content 2880 $v_content = @gzdeflate($v_content); 2881 2882 // ----- Set header parameters 2883 $p_header['compressed_size'] = strlen($v_content); 2884 $p_header['compression'] = 8; 2885 } 2886 2887 // ----- Look for encryption 2888 /* 2889 if ((isset($p_options[PCLZIP_OPT_CRYPT])) 2890 && ($p_options[PCLZIP_OPT_CRYPT] != "")) { 2891 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ...."); 2892 2893 // Should be a random header 2894 $v_header = 'xxxxxxxxxxxx'; 2895 $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed, 2896 $p_header['compressed_size'], 2897 $v_header, 2654 2898 $p_header['crc'], 2655 2899 "test"); 2656 2657 $p_header['compressed_size'] += 12; 2658 $p_header['flag'] = 1; 2659 2660 // ----- Add the header to the data 2661 $v_content_compressed = $v_header.$v_content_compressed; 2662 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed).""); 2663 } 2664 */ 2665 2666 // ----- Call the header generation 2667 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { 2668 @fclose($v_file); 2669 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2670 return $v_result; 2671 } 2672 2673 // ----- Write the compressed (or not) content 2674 @fwrite($this->zip_fd, 2675 $v_content_compressed, $p_header['compressed_size']); 2676 2677 // ----- Close the file 2678 @fclose($v_file); 2679 } 2680 2681 // ----- Look for a directory 2682 else { 2683 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder"); 2684 // ----- Look for directory last '/' 2685 if (@substr($p_header['stored_filename'], -1) != '/') { 2686 $p_header['stored_filename'] .= '/'; 2687 } 2688 2689 // ----- Set the file properties 2690 $p_header['size'] = 0; 2691 //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked 2692 $p_header['external'] = 0x00000010; // Value for a folder : to be checked 2693 2694 // ----- Call the header generation 2695 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) 2696 { 2697 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2698 return $v_result; 2699 } 2700 } 2701 } 2702 2703 // ----- Look for post-add callback 2704 if (isset($p_options[PCLZIP_CB_POST_ADD])) { 2705 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_ADD]."()') is defined for the extraction"); 2706 2707 // ----- Generate a local information 2708 $v_local_header = array(); 2709 $this->privConvertHeader2FileInfo($p_header, $v_local_header); 2710 2711 // ----- Call the callback 2712 // Here I do not use call_user_func() because I need to send a reference to the 2713 // header. 2714 eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);'); 2715 if ($v_result == 0) { 2716 // ----- Ignored 2717 $v_result = 1; 2718 } 2719 2720 // ----- Update the informations 2721 // Nothing can be modified 2722 } 2723 2724 // ----- Return 2725 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2726 return $v_result; 2900 2901 $p_header['compressed_size'] += 12; 2902 $p_header['flag'] = 1; 2903 2904 // ----- Add the header to the data 2905 $v_content_compressed = $v_header.$v_content_compressed; 2906 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed).""); 2907 } 2908 */ 2909 2910 // ----- Call the header generation 2911 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { 2912 @fclose($v_file); 2913 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2914 return $v_result; 2915 } 2916 2917 // ----- Write the compressed (or not) content 2918 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); 2919 2920 } 2921 2922 } 2923 2924 // ----- Look for a virtual file (a file from string) 2925 else if ($p_filedescr['type'] == 'virtual_file') { 2926 2927 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Add by string"); 2928 $v_content = $p_filedescr['content']; 2929 2930 // ----- Calculate the CRC 2931 $p_header['crc'] = @crc32($v_content); 2932 2933 // ----- Look for no compression 2934 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { 2935 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed"); 2936 // ----- Set header parameters 2937 $p_header['compressed_size'] = $p_header['size']; 2938 $p_header['compression'] = 0; 2939 } 2940 2941 // ----- Look for normal compression 2942 else { 2943 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed"); 2944 // ----- Compress the content 2945 $v_content = @gzdeflate($v_content); 2946 2947 // ----- Set header parameters 2948 $p_header['compressed_size'] = strlen($v_content); 2949 $p_header['compression'] = 8; 2950 } 2951 2952 // ----- Look for encryption 2953 /* 2954 if ((isset($p_options[PCLZIP_OPT_CRYPT])) 2955 && ($p_options[PCLZIP_OPT_CRYPT] != "")) { 2956 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ...."); 2957 2958 // Should be a random header 2959 $v_header = 'xxxxxxxxxxxx'; 2960 $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed, 2961 $p_header['compressed_size'], 2962 $v_header, 2963 $p_header['crc'], 2964 "test"); 2965 2966 $p_header['compressed_size'] += 12; 2967 $p_header['flag'] = 1; 2968 2969 // ----- Add the header to the data 2970 $v_content_compressed = $v_header.$v_content_compressed; 2971 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed).""); 2972 } 2973 */ 2974 2975 // ----- Call the header generation 2976 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { 2977 @fclose($v_file); 2978 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2979 return $v_result; 2980 } 2981 2982 // ----- Write the compressed (or not) content 2983 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); 2984 } 2985 2986 // ----- Look for a directory 2987 else if ($p_filedescr['type'] == 'folder') { 2988 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder"); 2989 // ----- Look for directory last '/' 2990 if (@substr($p_header['stored_filename'], -1) != '/') { 2991 $p_header['stored_filename'] .= '/'; 2992 } 2993 2994 // ----- Set the file properties 2995 $p_header['size'] = 0; 2996 //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked 2997 $p_header['external'] = 0x00000010; // Value for a folder : to be checked 2998 2999 // ----- Call the header generation 3000 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) 3001 { 3002 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3003 return $v_result; 3004 } 3005 } 3006 } 3007 3008 // ----- Look for post-add callback 3009 if (isset($p_options[PCLZIP_CB_POST_ADD])) { 3010 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_ADD]."()') is defined for the extraction"); 3011 3012 // ----- Generate a local information 3013 $v_local_header = array(); 3014 $this->privConvertHeader2FileInfo($p_header, $v_local_header); 3015 3016 // ----- Call the callback 3017 // Here I do not use call_user_func() because I need to send a reference to the 3018 // header. 3019 eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);'); 3020 if ($v_result == 0) { 3021 // ----- Ignored 3022 $v_result = 1; 3023 } 3024 3025 // ----- Update the informations 3026 // Nothing can be modified 3027 } 3028 3029 // ----- Return 3030 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3031 return $v_result; 3032 } 3033 // -------------------------------------------------------------------------------- 3034 3035 // -------------------------------------------------------------------------------- 3036 // Function : privAddFileUsingTempFile() 3037 // Description : 3038 // Parameters : 3039 // Return Values : 3040 // -------------------------------------------------------------------------------- 3041 function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) 3042 { 3043 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileUsingTempFile", "filename='".$p_filedescr['filename']."'"); 3044 $v_result=PCLZIP_ERR_NO_ERROR; 3045 3046 // ----- Working variable 3047 $p_filename = $p_filedescr['filename']; 3048 3049 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file"); 3050 3051 // ----- Open the source file 3052 if (($v_file = @fopen($p_filename, "rb")) == 0) { 3053 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); 3054 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3055 return PclZip::errorCode(); 3056 } 3057 3058 // ----- Creates a compressed temporary file 3059 $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; 3060 if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { 3061 fclose($v_file); 3062 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); 3063 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3064 return PclZip::errorCode(); 3065 } 3066 3067 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks 3068 $v_size = filesize($p_filename); 3069 while ($v_size != 0) { 3070 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 3071 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes"); 3072 $v_buffer = fread($v_file, $v_read_size); 3073 //$v_binary_data = pack('a'.$v_read_size, $v_buffer); 3074 @gzputs($v_file_compressed, $v_buffer, $v_read_size); 3075 $v_size -= $v_read_size; 3076 } 3077 3078 // ----- Close the file 3079 @fclose($v_file); 3080 @gzclose($v_file_compressed); 3081 3082 // ----- Check the minimum file size 3083 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "gzip file size ".filesize($v_gzip_temp_name)); 3084 if (filesize($v_gzip_temp_name) < 18) { 3085 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); 3086 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3087 return PclZip::errorCode(); 3088 } 3089 3090 // ----- Extract the compressed attributes 3091 if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { 3092 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); 3093 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3094 return PclZip::errorCode(); 3095 } 3096 3097 // ----- Read the gzip file header 3098 $v_binary_data = @fread($v_file_compressed, 10); 3099 $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data); 3100 3101 // ----- Check some parameters 3102 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[id1]='.bin2hex($v_data_header['id1'])); 3103 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[id2]='.bin2hex($v_data_header['id2'])); 3104 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[cm]='.bin2hex($v_data_header['cm'])); 3105 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[flag]='.bin2hex($v_data_header['flag'])); 3106 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[mtime]='.$v_data_header['mtime']); 3107 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[xfl]='.bin2hex($v_data_header['xfl'])); 3108 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[os]='.bin2hex($v_data_header['os'])); 3109 $v_data_header['os'] = bin2hex($v_data_header['os']); 3110 3111 // ----- Read the gzip file footer 3112 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position after header ".ftell($v_file_compressed)); 3113 @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8); 3114 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position at beginning of footer ".ftell($v_file_compressed)); 3115 $v_binary_data = @fread($v_file_compressed, 8); 3116 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position after footer ".ftell($v_file_compressed)); 3117 $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data); 3118 3119 // ----- Set the attributes 3120 $p_header['compression'] = ord($v_data_header['cm']); 3121 //$p_header['mtime'] = $v_data_header['mtime']; 3122 $p_header['crc'] = $v_data_footer['crc']; 3123 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Compressed size ".(filesize($v_gzip_temp_name)-18)); 3124 $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18; 3125 3126 // ----- Close the file 3127 @fclose($v_file_compressed); 3128 3129 // ----- Call the header generation 3130 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { 3131 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3132 return $v_result; 3133 } 3134 3135 // ----- Add the compressed data 3136 if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) 3137 { 3138 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); 3139 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3140 return PclZip::errorCode(); 3141 } 3142 3143 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks 3144 fseek($v_file_compressed, 10); 3145 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position before reading compressed data ".ftell($v_file_compressed)); 3146 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, ' '.$p_header['compressed_size'].' bytes to read'); 3147 $v_size = $p_header['compressed_size']; 3148 while ($v_size != 0) 3149 { 3150 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 3151 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes"); 3152 $v_buffer = fread($v_file_compressed, $v_read_size); 3153 //$v_binary_data = pack('a'.$v_read_size, $v_buffer); 3154 @fwrite($this->zip_fd, $v_buffer, $v_read_size); 3155 $v_size -= $v_read_size; 3156 } 3157 3158 // ----- Close the file 3159 @fclose($v_file_compressed); 3160 3161 // ----- Unlink the temporary file 3162 @unlink($v_gzip_temp_name); 3163 3164 // ----- Return 3165 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3166 return $v_result; 2727 3167 } 2728 3168 // -------------------------------------------------------------------------------- … … 2738 3178 function privCalculateStoredFilename(&$p_filedescr, &$p_options) 2739 3179 { 2740 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCalculateStoredFilename", "filename='".$p_filedescr['filename']."'"); 2741 $v_result=1; 2742 2743 // ----- Working variables 2744 $p_filename = $p_filedescr['filename']; 2745 if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { 2746 $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; 2747 } 2748 else { 2749 $p_add_dir = ''; 2750 } 2751 if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { 2752 $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; 2753 } 2754 else { 2755 $p_remove_dir = ''; 2756 } 2757 if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { 2758 $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; 2759 } 2760 else { 2761 $p_remove_all_dir = 0; 2762 } 2763 2764 // ----- Look for full name change 2765 if (isset($p_filedescr['new_full_name'])) { 2766 $v_stored_filename = $p_filedescr['new_full_name']; 2767 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing full name of '".$p_filename."' for '".$v_stored_filename."'"); 2768 } 2769 2770 // ----- Look for path and/or short name change 2771 else { 2772 2773 // ----- Look for short name change 2774 if (isset($p_filedescr['new_short_name'])) { 2775 $v_path_info = pathinfo($p_filename); 2776 $v_dir = ''; 2777 if ($v_path_info['dirname'] != '') { 2778 $v_dir = $v_path_info['dirname'].'/'; 2779 } 2780 $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; 2781 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing short name of '".$p_filename."' for '".$v_stored_filename."'"); 2782 } 2783 else { 2784 // ----- Calculate the stored filename 2785 $v_stored_filename = $p_filename; 2786 } 2787 2788 // ----- Look for all path to remove 2789 if ($p_remove_all_dir) { 2790 $v_stored_filename = basename($p_filename); 2791 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove all path selected change '".$p_filename."' for '".$v_stored_filename."'"); 2792 } 2793 // ----- Look for partial path remove 2794 else if ($p_remove_dir != "") { 2795 if (substr($p_remove_dir, -1) != '/') 2796 $p_remove_dir .= "/"; 2797 2798 if ( (substr($p_filename, 0, 2) == "./") 2799 || (substr($p_remove_dir, 0, 2) == "./")) { 2800 2801 if ( (substr($p_filename, 0, 2) == "./") 2802 && (substr($p_remove_dir, 0, 2) != "./")) { 2803 $p_remove_dir = "./".$p_remove_dir; 2804 } 2805 if ( (substr($p_filename, 0, 2) != "./") 2806 && (substr($p_remove_dir, 0, 2) == "./")) { 2807 $p_remove_dir = substr($p_remove_dir, 2); 2808 } 2809 } 2810 2811 $v_compare = PclZipUtilPathInclusion($p_remove_dir, 2812 $v_stored_filename); 2813 if ($v_compare > 0) { 2814 if ($v_compare == 2) { 2815 $v_stored_filename = ""; 2816 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Path to remove is the current folder"); 2817 } 2818 else { 2819 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove path '$p_remove_dir' in file '$v_stored_filename'"); 2820 $v_stored_filename = substr($v_stored_filename, 2821 strlen($p_remove_dir)); 2822 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Result is '$v_stored_filename'"); 2823 } 2824 } 2825 } 2826 // ----- Look for path to add 2827 if ($p_add_dir != "") { 2828 if (substr($p_add_dir, -1) == "/") 2829 $v_stored_filename = $p_add_dir.$v_stored_filename; 2830 else 2831 $v_stored_filename = $p_add_dir."/".$v_stored_filename; 2832 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_filename' = '$v_stored_filename'"); 2833 } 2834 } 2835 2836 // ----- Filename (reduce the path of stored name) 2837 $v_stored_filename = PclZipUtilPathReduction($v_stored_filename); 2838 $p_filedescr['stored_filename'] = $v_stored_filename; 2839 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Stored filename will be '".$p_filedescr['stored_filename']."', strlen ".strlen($p_filedescr['stored_filename'])); 2840 2841 // ----- Return 2842 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2843 return $v_result; 3180 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCalculateStoredFilename", "filename='".$p_filedescr['filename']."'"); 3181 $v_result=1; 3182 3183 // ----- Working variables 3184 $p_filename = $p_filedescr['filename']; 3185 if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { 3186 $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; 3187 } 3188 else { 3189 $p_add_dir = ''; 3190 } 3191 if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { 3192 $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; 3193 } 3194 else { 3195 $p_remove_dir = ''; 3196 } 3197 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Remove path ='".$p_remove_dir."'"); 3198 if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { 3199 $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; 3200 } 3201 else { 3202 $p_remove_all_dir = 0; 3203 } 3204 3205 // ----- Look for full name change 3206 if (isset($p_filedescr['new_full_name'])) { 3207 // ----- Remove drive letter if any 3208 $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']); 3209 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing full name of '".$p_filename."' for '".$v_stored_filename."'"); 3210 } 3211 3212 // ----- Look for path and/or short name change 3213 else { 3214 3215 // ----- Look for short name change 3216 // Its when we cahnge just the filename but not the path 3217 if (isset($p_filedescr['new_short_name'])) { 3218 $v_path_info = pathinfo($p_filename); 3219 $v_dir = ''; 3220 if ($v_path_info['dirname'] != '') { 3221 $v_dir = $v_path_info['dirname'].'/'; 3222 } 3223 $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; 3224 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing short name of '".$p_filename."' for '".$v_stored_filename."'"); 3225 } 3226 else { 3227 // ----- Calculate the stored filename 3228 $v_stored_filename = $p_filename; 3229 } 3230 3231 // ----- Look for all path to remove 3232 if ($p_remove_all_dir) { 3233 $v_stored_filename = basename($p_filename); 3234 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove all path selected change '".$p_filename."' for '".$v_stored_filename."'"); 3235 } 3236 // ----- Look for partial path remove 3237 else if ($p_remove_dir != "") { 3238 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Partial path to remove"); 3239 if (substr($p_remove_dir, -1) != '/') 3240 $p_remove_dir .= "/"; 3241 3242 if ( (substr($p_filename, 0, 2) == "./") 3243 || (substr($p_remove_dir, 0, 2) == "./")) { 3244 3245 if ( (substr($p_filename, 0, 2) == "./") 3246 && (substr($p_remove_dir, 0, 2) != "./")) { 3247 $p_remove_dir = "./".$p_remove_dir; 3248 } 3249 if ( (substr($p_filename, 0, 2) != "./") 3250 && (substr($p_remove_dir, 0, 2) == "./")) { 3251 $p_remove_dir = substr($p_remove_dir, 2); 3252 } 3253 } 3254 3255 $v_compare = PclZipUtilPathInclusion($p_remove_dir, 3256 $v_stored_filename); 3257 if ($v_compare > 0) { 3258 if ($v_compare == 2) { 3259 $v_stored_filename = ""; 3260 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Path to remove is the current folder"); 3261 } 3262 else { 3263 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove path '$p_remove_dir' in file '$v_stored_filename'"); 3264 $v_stored_filename = substr($v_stored_filename, 3265 strlen($p_remove_dir)); 3266 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Result is '$v_stored_filename'"); 3267 } 3268 } 3269 } 3270 3271 // ----- Remove drive letter if any 3272 $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename); 3273 3274 // ----- Look for path to add 3275 if ($p_add_dir != "") { 3276 if (substr($p_add_dir, -1) == "/") 3277 $v_stored_filename = $p_add_dir.$v_stored_filename; 3278 else 3279 $v_stored_filename = $p_add_dir."/".$v_stored_filename; 3280 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_filename' = '$v_stored_filename'"); 3281 } 3282 } 3283 3284 // ----- Filename (reduce the path of stored name) 3285 $v_stored_filename = PclZipUtilPathReduction($v_stored_filename); 3286 $p_filedescr['stored_filename'] = $v_stored_filename; 3287 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Stored filename will be '".$p_filedescr['stored_filename']."', strlen ".strlen($p_filedescr['stored_filename'])); 3288 3289 // ----- Return 3290 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3291 return $v_result; 2844 3292 } 2845 3293 // -------------------------------------------------------------------------------- … … 2853 3301 function privWriteFileHeader(&$p_header) 2854 3302 { 2855 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"');2856 $v_result=1;2857 2858 // ----- Store the offset position of the file2859 $p_header['offset'] = ftell($this->zip_fd);2860 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'File offset of the header :'.$p_header['offset']);2861 2862 // ----- Transform UNIX mtime to DOS format mdate/mtime2863 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');2864 $v_date = getdate($p_header['mtime']);2865 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;2866 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];2867 2868 // ----- Packed data2869 $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,2870 $p_header['version_extracted'], $p_header['flag'],2871 $p_header['compression'], $v_mtime, $v_mdate,2872 $p_header['crc'], $p_header['compressed_size'],3303 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"'); 3304 $v_result=1; 3305 3306 // ----- Store the offset position of the file 3307 $p_header['offset'] = ftell($this->zip_fd); 3308 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'File offset of the header :'.$p_header['offset']); 3309 3310 // ----- Transform UNIX mtime to DOS format mdate/mtime 3311 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 3312 $v_date = getdate($p_header['mtime']); 3313 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; 3314 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; 3315 3316 // ----- Packed data 3317 $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, 3318 $p_header['version_extracted'], $p_header['flag'], 3319 $p_header['compression'], $v_mtime, $v_mdate, 3320 $p_header['crc'], $p_header['compressed_size'], 2873 3321 $p_header['size'], 2874 strlen($p_header['stored_filename']),3322 strlen($p_header['stored_filename']), 2875 3323 $p_header['extra_len']); 2876 3324 2877 // ----- Write the first 148 bytes of the header in the archive2878 fputs($this->zip_fd, $v_binary_data, 30);2879 2880 // ----- Write the variable fields2881 if (strlen($p_header['stored_filename']) != 0)2882 {2883 fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));2884 }2885 if ($p_header['extra_len'] != 0)2886 {2887 fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);2888 }2889 2890 // ----- Return2891 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2892 return $v_result;3325 // ----- Write the first 148 bytes of the header in the archive 3326 fputs($this->zip_fd, $v_binary_data, 30); 3327 3328 // ----- Write the variable fields 3329 if (strlen($p_header['stored_filename']) != 0) 3330 { 3331 fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); 3332 } 3333 if ($p_header['extra_len'] != 0) 3334 { 3335 fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); 3336 } 3337 3338 // ----- Return 3339 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3340 return $v_result; 2893 3341 } 2894 3342 // -------------------------------------------------------------------------------- … … 2902 3350 function privWriteCentralFileHeader(&$p_header) 2903 3351 { 2904 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"'); 2905 $v_result=1; 2906 2907 // TBC 2908 //for(reset($p_header); $key = key($p_header); next($p_header)) { 2909 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "header[$key] = ".$p_header[$key]); 2910 //} 2911 2912 // ----- Transform UNIX mtime to DOS format mdate/mtime 2913 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 2914 $v_date = getdate($p_header['mtime']); 2915 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; 2916 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; 2917 2918 // ----- Packed data 2919 $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, 2920 $p_header['version'], $p_header['version_extracted'], 2921 $p_header['flag'], $p_header['compression'], 3352 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"'); 3353 $v_result=1; 3354 3355 // TBC 3356 //for(reset($p_header); $key = key($p_header); next($p_header)) { 3357 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "header[$key] = ".$p_header[$key]); 3358 //} 3359 3360 // ----- Transform UNIX mtime to DOS format mdate/mtime 3361 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 3362 $v_date = getdate($p_header['mtime']); 3363 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; 3364 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; 3365 3366 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment size : \''.$p_header['comment_len'].'\''); 3367 3368 // ----- Packed data 3369 $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, 3370 $p_header['version'], $p_header['version_extracted'], 3371 $p_header['flag'], $p_header['compression'], 2922 3372 $v_mtime, $v_mdate, $p_header['crc'], 2923 $p_header['compressed_size'], $p_header['size'],2924 strlen($p_header['stored_filename']),3373 $p_header['compressed_size'], $p_header['size'], 3374 strlen($p_header['stored_filename']), 2925 3375 $p_header['extra_len'], $p_header['comment_len'], 2926 $p_header['disk'], $p_header['internal'],3376 $p_header['disk'], $p_header['internal'], 2927 3377 $p_header['external'], $p_header['offset']); 2928 3378 2929 // ----- Write the 42 bytes of the header in the zip file2930 fputs($this->zip_fd, $v_binary_data, 46);2931 2932 // ----- Write the variable fields2933 if (strlen($p_header['stored_filename']) != 0)2934 {2935 fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));2936 }2937 if ($p_header['extra_len'] != 0)2938 {2939 fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);2940 }2941 if ($p_header['comment_len'] != 0)2942 {2943 fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);2944 }2945 2946 // ----- Return2947 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2948 return $v_result;3379 // ----- Write the 42 bytes of the header in the zip file 3380 fputs($this->zip_fd, $v_binary_data, 46); 3381 3382 // ----- Write the variable fields 3383 if (strlen($p_header['stored_filename']) != 0) 3384 { 3385 fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); 3386 } 3387 if ($p_header['extra_len'] != 0) 3388 { 3389 fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); 3390 } 3391 if ($p_header['comment_len'] != 0) 3392 { 3393 fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']); 3394 } 3395 3396 // ----- Return 3397 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3398 return $v_result; 2949 3399 } 2950 3400 // -------------------------------------------------------------------------------- … … 2958 3408 function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) 2959 3409 { 2960 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralHeader", 'nb_entries='.$p_nb_entries.', size='.$p_size.', offset='.$p_offset.', comment="'.$p_comment.'"');2961 $v_result=1;2962 2963 // ----- Packed data2964 $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,2965 $p_nb_entries, $p_size,3410 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralHeader", 'nb_entries='.$p_nb_entries.', size='.$p_size.', offset='.$p_offset.', comment="'.$p_comment.'"'); 3411 $v_result=1; 3412 3413 // ----- Packed data 3414 $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, 3415 $p_nb_entries, $p_size, 2966 3416 $p_offset, strlen($p_comment)); 2967 3417 2968 // ----- Write the 22 bytes of the header in the zip file2969 fputs($this->zip_fd, $v_binary_data, 22);2970 2971 // ----- Write the variable fields2972 if (strlen($p_comment) != 0)2973 {2974 fputs($this->zip_fd, $p_comment, strlen($p_comment));2975 }2976 2977 // ----- Return2978 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2979 return $v_result;3418 // ----- Write the 22 bytes of the header in the zip file 3419 fputs($this->zip_fd, $v_binary_data, 22); 3420 3421 // ----- Write the variable fields 3422 if (strlen($p_comment) != 0) 3423 { 3424 fputs($this->zip_fd, $p_comment, strlen($p_comment)); 3425 } 3426 3427 // ----- Return 3428 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3429 return $v_result; 2980 3430 } 2981 3431 // -------------------------------------------------------------------------------- … … 2989 3439 function privList(&$p_list) 2990 3440 { 2991 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privList", "list");2992 $v_result=1;2993 2994 // ----- Magic quotes trick2995 $this->privDisableMagicQuotes();2996 2997 // ----- Open the zip file2998 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");2999 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)3000 {3001 // ----- Magic quotes trick3002 $this->privSwapBackMagicQuotes();3003 3004 // ----- Error log3005 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');3006 3007 // ----- Return3008 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());3009 return PclZip::errorCode();3010 }3011 3012 // ----- Read the central directory informations3013 $v_central_dir = array();3014 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)3015 {3016 $this->privSwapBackMagicQuotes();3017 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3018 return $v_result;3019 }3020 3021 // ----- Go to beginning of Central Dir3022 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Offset : ".$v_central_dir['offset']."'");3023 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");3024 @rewind($this->zip_fd);3025 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");3026 if (@fseek($this->zip_fd, $v_central_dir['offset']))3027 {3028 $this->privSwapBackMagicQuotes();3029 3030 // ----- Error log3031 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');3032 3033 // ----- Return3034 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());3035 return PclZip::errorCode();3036 }3037 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");3038 3039 // ----- Read each entry3040 for ($i=0; $i<$v_central_dir['entries']; $i++)3041 {3042 // ----- Read the file header3043 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)3044 {3045 $this->privSwapBackMagicQuotes();3046 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3047 return $v_result;3048 }3049 $v_header['index'] = $i;3050 3051 // ----- Get the only interesting attributes3052 $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);3053 unset($v_header);3054 }3055 3056 // ----- Close the zip file3057 $this->privCloseFd();3058 3059 // ----- Magic quotes trick3060 $this->privSwapBackMagicQuotes();3061 3062 // ----- Return3063 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3064 return $v_result;3441 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privList", "list"); 3442 $v_result=1; 3443 3444 // ----- Magic quotes trick 3445 $this->privDisableMagicQuotes(); 3446 3447 // ----- Open the zip file 3448 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 3449 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) 3450 { 3451 // ----- Magic quotes trick 3452 $this->privSwapBackMagicQuotes(); 3453 3454 // ----- Error log 3455 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); 3456 3457 // ----- Return 3458 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3459 return PclZip::errorCode(); 3460 } 3461 3462 // ----- Read the central directory informations 3463 $v_central_dir = array(); 3464 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 3465 { 3466 $this->privSwapBackMagicQuotes(); 3467 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3468 return $v_result; 3469 } 3470 3471 // ----- Go to beginning of Central Dir 3472 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Offset : ".$v_central_dir['offset']."'"); 3473 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); 3474 @rewind($this->zip_fd); 3475 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); 3476 if (@fseek($this->zip_fd, $v_central_dir['offset'])) 3477 { 3478 $this->privSwapBackMagicQuotes(); 3479 3480 // ----- Error log 3481 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 3482 3483 // ----- Return 3484 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3485 return PclZip::errorCode(); 3486 } 3487 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); 3488 3489 // ----- Read each entry 3490 for ($i=0; $i<$v_central_dir['entries']; $i++) 3491 { 3492 // ----- Read the file header 3493 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) 3494 { 3495 $this->privSwapBackMagicQuotes(); 3496 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3497 return $v_result; 3498 } 3499 $v_header['index'] = $i; 3500 3501 // ----- Get the only interesting attributes 3502 $this->privConvertHeader2FileInfo($v_header, $p_list[$i]); 3503 unset($v_header); 3504 } 3505 3506 // ----- Close the zip file 3507 $this->privCloseFd(); 3508 3509 // ----- Magic quotes trick 3510 $this->privSwapBackMagicQuotes(); 3511 3512 // ----- Return 3513 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3514 return $v_result; 3065 3515 } 3066 3516 // -------------------------------------------------------------------------------- … … 3072 3522 // entries and extract the interesting parameters that will be given back. 3073 3523 // The resulting file infos are set in the array $p_info 3074 // $p_info['filename'] : Filename with full path. Given by user (add), 3075 // extracted in the filesystem (extract). 3076 // $p_info['stored_filename'] : Stored filename in the archive. 3077 // $p_info['size'] = Size of the file. 3078 // $p_info['compressed_size'] = Compressed size of the file. 3079 // $p_info['mtime'] = Last modification date of the file. 3080 // $p_info['comment'] = Comment associated with the file. 3081 // $p_info['folder'] = true/false : indicates if the entry is a folder or not. 3082 // $p_info['status'] = status of the action on the file. 3524 // $p_info['filename'] : Filename with full path. Given by user (add), 3525 // extracted in the filesystem (extract). 3526 // $p_info['stored_filename'] : Stored filename in the archive. 3527 // $p_info['size'] = Size of the file. 3528 // $p_info['compressed_size'] = Compressed size of the file. 3529 // $p_info['mtime'] = Last modification date of the file. 3530 // $p_info['comment'] = Comment associated with the file. 3531 // $p_info['folder'] = true/false : indicates if the entry is a folder or not. 3532 // $p_info['status'] = status of the action on the file. 3533 // $p_info['crc'] = CRC of the file content. 3083 3534 // Parameters : 3084 3535 // Return Values : … … 3086 3537 function privConvertHeader2FileInfo($p_header, &$p_info) 3087 3538 { 3088 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privConvertHeader2FileInfo", "Filename='".$p_header['filename']."'"); 3089 $v_result=1; 3090 3091 // ----- Get the interesting attributes 3092 $p_info['filename'] = $p_header['filename']; 3093 $p_info['stored_filename'] = $p_header['stored_filename']; 3094 $p_info['size'] = $p_header['size']; 3095 $p_info['compressed_size'] = $p_header['compressed_size']; 3096 $p_info['mtime'] = $p_header['mtime']; 3097 $p_info['comment'] = $p_header['comment']; 3098 $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); 3099 $p_info['index'] = $p_header['index']; 3100 $p_info['status'] = $p_header['status']; 3101 3102 // ----- Return 3103 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3104 return $v_result; 3539 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privConvertHeader2FileInfo", "Filename='".$p_header['filename']."'"); 3540 $v_result=1; 3541 3542 // ----- Get the interesting attributes 3543 $p_info['filename'] = $p_header['filename']; 3544 $p_info['stored_filename'] = $p_header['stored_filename']; 3545 $p_info['size'] = $p_header['size']; 3546 $p_info['compressed_size'] = $p_header['compressed_size']; 3547 $p_info['mtime'] = $p_header['mtime']; 3548 $p_info['comment'] = $p_header['comment']; 3549 $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); 3550 $p_info['index'] = $p_header['index']; 3551 $p_info['status'] = $p_header['status']; 3552 $p_info['crc'] = $p_header['crc']; 3553 3554 // ----- Return 3555 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3556 return $v_result; 3105 3557 } 3106 3558 // -------------------------------------------------------------------------------- … … 3112 3564 // Parameters : 3113 3565 // $p_file_list : An array where will be placed the properties of each 3114 // extracted file3566 // extracted file 3115 3567 // $p_path : Path to add while writing the extracted files 3116 3568 // $p_remove_path : Path to remove (from the file memorized path) while writing the 3117 // extracted files. If the path does not match the file path,3118 // the file is extracted with its memorized path.3119 // $p_remove_path does not apply to 'list' mode.3120 // $p_path and $p_remove_path are commulative.3569 // extracted files. If the path does not match the file path, 3570 // the file is extracted with its memorized path. 3571 // $p_remove_path does not apply to 'list' mode. 3572 // $p_path and $p_remove_path are commulative. 3121 3573 // Return Values : 3122 3574 // 1 on success,0 or less on error (see error code list) … … 3124 3576 function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) 3125 3577 { 3126 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privExtractByRule", "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");3127 $v_result=1;3128 3129 // ----- Magic quotes trick3130 $this->privDisableMagicQuotes();3131 3132 // ----- Check the path3133 if ( ($p_path == "")3134 || ( (substr($p_path, 0, 1) != "/")3135 && (substr($p_path, 0, 3) != "../")3578 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privExtractByRule", "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'"); 3579 $v_result=1; 3580 3581 // ----- Magic quotes trick 3582 $this->privDisableMagicQuotes(); 3583 3584 // ----- Check the path 3585 if ( ($p_path == "") 3586 || ( (substr($p_path, 0, 1) != "/") 3587 && (substr($p_path, 0, 3) != "../") 3136 3588 && (substr($p_path,1,2)!=":/"))) 3137 $p_path = "./".$p_path;3138 3139 // ----- Reduce the path last (and duplicated) '/'3140 if (($p_path != "./") && ($p_path != "/"))3141 {3142 // ----- Look for the path end '/'3143 while (substr($p_path, -1) == "/")3144 {3145 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'");3146 $p_path = substr($p_path, 0, strlen($p_path)-1);3147 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]");3148 }3149 }3150 3151 // ----- Look for path to remove format (should end by /)3152 if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))3153 {3154 $p_remove_path .= '/';3155 }3156 $p_remove_path_size = strlen($p_remove_path);3157 3158 // ----- Open the zip file3159 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");3160 if (($v_result = $this->privOpenFd('rb')) != 1)3161 {3162 $this->privSwapBackMagicQuotes();3163 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3164 return $v_result;3165 }3166 3167 // ----- Read the central directory informations3168 $v_central_dir = array();3169 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)3170 {3171 // ----- Close the zip file3172 $this->privCloseFd();3173 $this->privSwapBackMagicQuotes();3174 3175 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3176 return $v_result;3177 }3178 3179 // ----- Start at beginning of Central Dir3180 $v_pos_entry = $v_central_dir['offset'];3181 3182 // ----- Read each entry3183 $j_start = 0;3184 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)3185 {3186 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry : '$i'");3187 3188 // ----- Read next Central dir entry3189 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position before rewind : ".ftell($this->zip_fd)."'");3190 @rewind($this->zip_fd);3191 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position after rewind : ".ftell($this->zip_fd)."'");3192 if (@fseek($this->zip_fd, $v_pos_entry))3193 {3194 // ----- Close the zip file3195 $this->privCloseFd();3196 $this->privSwapBackMagicQuotes();3197 3198 // ----- Error log3199 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');3200 3201 // ----- Return3202 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());3203 return PclZip::errorCode();3204 }3205 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position after fseek : ".ftell($this->zip_fd)."'");3206 3207 // ----- Read the file header3208 $v_header = array();3209 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)3210 {3211 // ----- Close the zip file3212 $this->privCloseFd();3213 $this->privSwapBackMagicQuotes();3214 3215 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3216 return $v_result;3217 }3218 3219 // ----- Store the index3220 $v_header['index'] = $i;3221 3222 // ----- Store the file position3223 $v_pos_entry = ftell($this->zip_fd);3224 3225 // ----- Look for the specific extract rules3226 $v_extract = false;3227 3228 // ----- Look for extract by name rule3229 if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))3230 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {3231 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'");3232 3233 // ----- Look if the filename is in the list3234 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {3235 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'");3236 3237 // ----- Look for a directory3238 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {3239 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory");3240 3241 // ----- Look if the directory is in the filename path3242 if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))3243 && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {3244 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path");3245 $v_extract = true;3246 }3247 }3248 // ----- Look for a filename3249 elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {3250 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one.");3251 $v_extract = true;3252 }3253 }3254 }3255 3256 // ----- Look for extract by ereg rule3257 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))3258 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {3259 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'");3260 3261 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {3262 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");3263 $v_extract = true;3264 }3265 }3266 3267 // ----- Look for extract by preg rule3268 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))3269 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {3270 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'");3271 3272 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {3273 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");3274 $v_extract = true;3275 }3276 }3277 3278 // ----- Look for extract by index rule3279 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))3280 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {3281 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'");3282 3283 // ----- Look if the index is in the list3284 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {3285 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]");3286 3287 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {3288 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");3289 $v_extract = true;3290 }3291 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {3292 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop");3293 $j_start = $j+1;3294 }3295 3296 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {3297 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop");3298 break;3299 }3300 }3301 }3302 3303 // ----- Look for no rule, which means extract all the archive3304 else {3305 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with no rule (extract all)");3306 $v_extract = true;3307 }3589 $p_path = "./".$p_path; 3590 3591 // ----- Reduce the path last (and duplicated) '/' 3592 if (($p_path != "./") && ($p_path != "/")) 3593 { 3594 // ----- Look for the path end '/' 3595 while (substr($p_path, -1) == "/") 3596 { 3597 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'"); 3598 $p_path = substr($p_path, 0, strlen($p_path)-1); 3599 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]"); 3600 } 3601 } 3602 3603 // ----- Look for path to remove format (should end by /) 3604 if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/')) 3605 { 3606 $p_remove_path .= '/'; 3607 } 3608 $p_remove_path_size = strlen($p_remove_path); 3609 3610 // ----- Open the zip file 3611 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 3612 if (($v_result = $this->privOpenFd('rb')) != 1) 3613 { 3614 $this->privSwapBackMagicQuotes(); 3615 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3616 return $v_result; 3617 } 3618 3619 // ----- Read the central directory informations 3620 $v_central_dir = array(); 3621 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 3622 { 3623 // ----- Close the zip file 3624 $this->privCloseFd(); 3625 $this->privSwapBackMagicQuotes(); 3626 3627 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3628 return $v_result; 3629 } 3630 3631 // ----- Start at beginning of Central Dir 3632 $v_pos_entry = $v_central_dir['offset']; 3633 3634 // ----- Read each entry 3635 $j_start = 0; 3636 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) 3637 { 3638 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry : '$i'"); 3639 3640 // ----- Read next Central dir entry 3641 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position before rewind : ".ftell($this->zip_fd)."'"); 3642 @rewind($this->zip_fd); 3643 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position after rewind : ".ftell($this->zip_fd)."'"); 3644 if (@fseek($this->zip_fd, $v_pos_entry)) 3645 { 3646 // ----- Close the zip file 3647 $this->privCloseFd(); 3648 $this->privSwapBackMagicQuotes(); 3649 3650 // ----- Error log 3651 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 3652 3653 // ----- Return 3654 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3655 return PclZip::errorCode(); 3656 } 3657 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position after fseek : ".ftell($this->zip_fd)."'"); 3658 3659 // ----- Read the file header 3660 $v_header = array(); 3661 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) 3662 { 3663 // ----- Close the zip file 3664 $this->privCloseFd(); 3665 $this->privSwapBackMagicQuotes(); 3666 3667 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3668 return $v_result; 3669 } 3670 3671 // ----- Store the index 3672 $v_header['index'] = $i; 3673 3674 // ----- Store the file position 3675 $v_pos_entry = ftell($this->zip_fd); 3676 3677 // ----- Look for the specific extract rules 3678 $v_extract = false; 3679 3680 // ----- Look for extract by name rule 3681 if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) 3682 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { 3683 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'"); 3684 3685 // ----- Look if the filename is in the list 3686 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { 3687 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'"); 3688 3689 // ----- Look for a directory 3690 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { 3691 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory"); 3692 3693 // ----- Look if the directory is in the filename path 3694 if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) 3695 && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { 3696 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path"); 3697 $v_extract = true; 3698 } 3699 } 3700 // ----- Look for a filename 3701 elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { 3702 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one."); 3703 $v_extract = true; 3704 } 3705 } 3706 } 3707 3708 // ----- Look for extract by ereg rule 3709 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) 3710 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { 3711 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'"); 3712 3713 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) { 3714 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); 3715 $v_extract = true; 3716 } 3717 } 3718 3719 // ----- Look for extract by preg rule 3720 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) 3721 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { 3722 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'"); 3723 3724 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { 3725 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); 3726 $v_extract = true; 3727 } 3728 } 3729 3730 // ----- Look for extract by index rule 3731 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) 3732 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { 3733 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'"); 3734 3735 // ----- Look if the index is in the list 3736 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { 3737 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]"); 3738 3739 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { 3740 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range"); 3741 $v_extract = true; 3742 } 3743 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { 3744 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop"); 3745 $j_start = $j+1; 3746 } 3747 3748 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { 3749 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop"); 3750 break; 3751 } 3752 } 3753 } 3754 3755 // ----- Look for no rule, which means extract all the archive 3756 else { 3757 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with no rule (extract all)"); 3758 $v_extract = true; 3759 } 3308 3760 3309 3761 // ----- Check compression method 3310 3762 if ( ($v_extract) 3311 && ( ($v_header['compression'] != 8)3312 && ($v_header['compression'] != 0))) {3313 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported compression method (".$v_header['compression'].")");3314 $v_header['status'] = 'unsupported_compression';3315 3316 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR3317 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))3318 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {3319 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");3320 3321 $this->privSwapBackMagicQuotes();3322 3323 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,3324 "Filename '".$v_header['stored_filename']."' is "3325 ."compressed by an unsupported compression "3326 ."method (".$v_header['compression'].") ");3327 3328 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());3329 return PclZip::errorCode();3330 } 3331 } 3332 3763 && ( ($v_header['compression'] != 8) 3764 && ($v_header['compression'] != 0))) { 3765 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported compression method (".$v_header['compression'].")"); 3766 $v_header['status'] = 'unsupported_compression'; 3767 3768 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 3769 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 3770 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 3771 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 3772 3773 $this->privSwapBackMagicQuotes(); 3774 3775 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, 3776 "Filename '".$v_header['stored_filename']."' is " 3777 ."compressed by an unsupported compression " 3778 ."method (".$v_header['compression'].") "); 3779 3780 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3781 return PclZip::errorCode(); 3782 } 3783 } 3784 3333 3785 // ----- Check encrypted files 3334 3786 if (($v_extract) && (($v_header['flag'] & 1) == 1)) { 3335 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported file encryption");3336 $v_header['status'] = 'unsupported_encryption';3337 3338 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR3339 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))3340 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {3341 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");3342 3343 $this->privSwapBackMagicQuotes();3344 3345 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,3346 "Unsupported encryption for "3347 ." filename '".$v_header['stored_filename']3787 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported file encryption"); 3788 $v_header['status'] = 'unsupported_encryption'; 3789 3790 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 3791 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 3792 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 3793 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 3794 3795 $this->privSwapBackMagicQuotes(); 3796 3797 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 3798 "Unsupported encryption for " 3799 ." filename '".$v_header['stored_filename'] 3348 3800 ."'"); 3349 3801 3350 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());3351 return PclZip::errorCode();3352 } 3353 }3354 3355 // ----- Look for real extraction3356 if (($v_extract) && ($v_header['status'] != 'ok')) {3357 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "No need for extract");3358 $v_result = $this->privConvertHeader2FileInfo($v_header,3359 $p_file_list[$v_nb_extracted++]);3360 if ($v_result != 1) {3361 $this->privCloseFd();3362 $this->privSwapBackMagicQuotes();3363 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3364 return $v_result;3365 }3366 3367 $v_extract = false;3368 }3369 3370 // ----- Look for real extraction3371 if ($v_extract)3372 {3373 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file '".$v_header['filename']."', index '$i'");3374 3375 // ----- Go to the file position3376 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");3377 @rewind($this->zip_fd);3378 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");3379 if (@fseek($this->zip_fd, $v_header['offset']))3380 {3381 // ----- Close the zip file3382 $this->privCloseFd();3383 3384 $this->privSwapBackMagicQuotes();3385 3386 // ----- Error log3387 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');3388 3389 // ----- Return3390 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());3391 return PclZip::errorCode();3392 }3393 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");3394 3395 // ----- Look for extraction as string3396 if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {3397 3398 // ----- Extracting the file3399 $v_result1 = $this->privExtractFileAsString($v_header, $v_string);3400 if ($v_result1 < 1) {3401 $this->privCloseFd();3402 $this->privSwapBackMagicQuotes();3403 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);3404 return $v_result1;3405 }3406 3407 // ----- Get the only interesting attributes3408 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)3409 {3410 // ----- Close the zip file3411 $this->privCloseFd();3412 $this->privSwapBackMagicQuotes();3413 3414 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3415 return $v_result;3416 }3417 3418 // ----- Set the file content3419 $p_file_list[$v_nb_extracted]['content'] = $v_string;3420 3421 // ----- Next extracted file3422 $v_nb_extracted++;3423 3424 // ----- Look for user callback abort3425 if ($v_result1 == 2) {3426 break;3427 }3428 }3429 // ----- Look for extraction in standard output3430 elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))3431 && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {3432 // ----- Extracting the file in standard output3433 $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);3434 if ($v_result1 < 1) {3435 $this->privCloseFd();3436 $this->privSwapBackMagicQuotes();3437 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);3438 return $v_result1;3439 }3440 3441 // ----- Get the only interesting attributes3442 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {3443 $this->privCloseFd();3444 $this->privSwapBackMagicQuotes();3445 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3446 return $v_result;3447 }3448 3449 // ----- Look for user callback abort3450 if ($v_result1 == 2) {3451 break;3452 }3453 }3454 // ----- Look for normal extraction3455 else {3456 // ----- Extracting the file3457 $v_result1 = $this->privExtractFile($v_header,3458 $p_path, $p_remove_path,3802 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3803 return PclZip::errorCode(); 3804 } 3805 } 3806 3807 // ----- Look for real extraction 3808 if (($v_extract) && ($v_header['status'] != 'ok')) { 3809 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "No need for extract"); 3810 $v_result = $this->privConvertHeader2FileInfo($v_header, 3811 $p_file_list[$v_nb_extracted++]); 3812 if ($v_result != 1) { 3813 $this->privCloseFd(); 3814 $this->privSwapBackMagicQuotes(); 3815 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3816 return $v_result; 3817 } 3818 3819 $v_extract = false; 3820 } 3821 3822 // ----- Look for real extraction 3823 if ($v_extract) 3824 { 3825 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file '".$v_header['filename']."', index '$i'"); 3826 3827 // ----- Go to the file position 3828 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); 3829 @rewind($this->zip_fd); 3830 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); 3831 if (@fseek($this->zip_fd, $v_header['offset'])) 3832 { 3833 // ----- Close the zip file 3834 $this->privCloseFd(); 3835 3836 $this->privSwapBackMagicQuotes(); 3837 3838 // ----- Error log 3839 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 3840 3841 // ----- Return 3842 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3843 return PclZip::errorCode(); 3844 } 3845 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); 3846 3847 // ----- Look for extraction as string 3848 if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) { 3849 3850 // ----- Extracting the file 3851 $v_result1 = $this->privExtractFileAsString($v_header, $v_string); 3852 if ($v_result1 < 1) { 3853 $this->privCloseFd(); 3854 $this->privSwapBackMagicQuotes(); 3855 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1); 3856 return $v_result1; 3857 } 3858 3859 // ----- Get the only interesting attributes 3860 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) 3861 { 3862 // ----- Close the zip file 3863 $this->privCloseFd(); 3864 $this->privSwapBackMagicQuotes(); 3865 3866 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3867 return $v_result; 3868 } 3869 3870 // ----- Set the file content 3871 $p_file_list[$v_nb_extracted]['content'] = $v_string; 3872 3873 // ----- Next extracted file 3874 $v_nb_extracted++; 3875 3876 // ----- Look for user callback abort 3877 if ($v_result1 == 2) { 3878 break; 3879 } 3880 } 3881 // ----- Look for extraction in standard output 3882 elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) 3883 && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { 3884 // ----- Extracting the file in standard output 3885 $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); 3886 if ($v_result1 < 1) { 3887 $this->privCloseFd(); 3888 $this->privSwapBackMagicQuotes(); 3889 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1); 3890 return $v_result1; 3891 } 3892 3893 // ----- Get the only interesting attributes 3894 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { 3895 $this->privCloseFd(); 3896 $this->privSwapBackMagicQuotes(); 3897 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3898 return $v_result; 3899 } 3900 3901 // ----- Look for user callback abort 3902 if ($v_result1 == 2) { 3903 break; 3904 } 3905 } 3906 // ----- Look for normal extraction 3907 else { 3908 // ----- Extracting the file 3909 $v_result1 = $this->privExtractFile($v_header, 3910 $p_path, $p_remove_path, 3459 3911 $p_remove_all_path, 3460 3912 $p_options); 3461 if ($v_result1 < 1) {3462 $this->privCloseFd();3463 $this->privSwapBackMagicQuotes();3464 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);3465 return $v_result1;3466 }3467 3468 // ----- Get the only interesting attributes3469 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)3470 {3471 // ----- Close the zip file3472 $this->privCloseFd();3473 $this->privSwapBackMagicQuotes();3474 3475 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3476 return $v_result;3477 }3478 3479 // ----- Look for user callback abort3480 if ($v_result1 == 2) {3481 break;3482 }3483 }3484 }3485 }3486 3487 // ----- Close the zip file3488 $this->privCloseFd();3489 $this->privSwapBackMagicQuotes();3490 3491 // ----- Return3492 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3493 return $v_result;3913 if ($v_result1 < 1) { 3914 $this->privCloseFd(); 3915 $this->privSwapBackMagicQuotes(); 3916 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1); 3917 return $v_result1; 3918 } 3919 3920 // ----- Get the only interesting attributes 3921 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) 3922 { 3923 // ----- Close the zip file 3924 $this->privCloseFd(); 3925 $this->privSwapBackMagicQuotes(); 3926 3927 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3928 return $v_result; 3929 } 3930 3931 // ----- Look for user callback abort 3932 if ($v_result1 == 2) { 3933 break; 3934 } 3935 } 3936 } 3937 } 3938 3939 // ----- Close the zip file 3940 $this->privCloseFd(); 3941 $this->privSwapBackMagicQuotes(); 3942 3943 // ----- Return 3944 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3945 return $v_result; 3494 3946 } 3495 3947 // -------------------------------------------------------------------------------- … … 3506 3958 function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) 3507 3959 { 3508 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");3509 $v_result=1;3510 3511 // ----- Read the file header3512 if (($v_result = $this->privReadFileHeader($v_header)) != 1)3513 {3514 // ----- Return3515 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3516 return $v_result;3517 }3518 3519 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");3520 3521 // ----- Check that the file header is coherent with $p_entry info3522 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {3523 // TBC3524 }3525 3526 // ----- Look for all path to remove3527 if ($p_remove_all_path == true) {3528 // ----- Look for folder entry that not need to be extracted3529 if (($p_entry['external']&0x00000010)==0x00000010) {3530 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The entry is a folder : need to be filtered");3531 3532 $p_entry['status'] = "filtered";3533 3534 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3535 return $v_result;3536 }3537 3538 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "All path is removed");3539 // ----- Get the basename of the path3540 $p_entry['filename'] = basename($p_entry['filename']);3541 }3542 3543 // ----- Look for path to remove3544 else if ($p_remove_path != "")3545 {3546 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look for some path to remove");3547 if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)3548 {3549 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '".$p_entry['filename']."'");3550 3551 // ----- Change the file status3552 $p_entry['status'] = "filtered";3553 3554 // ----- Return3555 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3556 return $v_result;3557 }3558 3559 $p_remove_path_size = strlen($p_remove_path);3560 if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)3561 {3562 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '".$p_entry['filename']."'");3563 3564 // ----- Remove the path3565 $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);3566 3567 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '".$p_entry['filename']."'");3568 }3569 }3570 3571 // ----- Add the path3572 if ($p_path != '') {3573 $p_entry['filename'] = $p_path."/".$p_entry['filename'];3574 }3575 3576 // ----- Check a base_dir_restriction3577 if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {3578 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Check the extract directory restriction");3579 $v_inclusion3580 = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],3581 $p_entry['filename']); 3582 if ($v_inclusion == 0) {3583 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction");3584 3585 PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,3586 "Filename '".$p_entry['filename']."' is "3960 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'"); 3961 $v_result=1; 3962 3963 // ----- Read the file header 3964 if (($v_result = $this->privReadFileHeader($v_header)) != 1) 3965 { 3966 // ----- Return 3967 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3968 return $v_result; 3969 } 3970 3971 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); 3972 3973 // ----- Check that the file header is coherent with $p_entry info 3974 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { 3975 // TBC 3976 } 3977 3978 // ----- Look for all path to remove 3979 if ($p_remove_all_path == true) { 3980 // ----- Look for folder entry that not need to be extracted 3981 if (($p_entry['external']&0x00000010)==0x00000010) { 3982 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The entry is a folder : need to be filtered"); 3983 3984 $p_entry['status'] = "filtered"; 3985 3986 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3987 return $v_result; 3988 } 3989 3990 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "All path is removed"); 3991 // ----- Get the basename of the path 3992 $p_entry['filename'] = basename($p_entry['filename']); 3993 } 3994 3995 // ----- Look for path to remove 3996 else if ($p_remove_path != "") 3997 { 3998 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look for some path to remove"); 3999 if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) 4000 { 4001 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '".$p_entry['filename']."'"); 4002 4003 // ----- Change the file status 4004 $p_entry['status'] = "filtered"; 4005 4006 // ----- Return 4007 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4008 return $v_result; 4009 } 4010 4011 $p_remove_path_size = strlen($p_remove_path); 4012 if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) 4013 { 4014 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '".$p_entry['filename']."'"); 4015 4016 // ----- Remove the path 4017 $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); 4018 4019 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '".$p_entry['filename']."'"); 4020 } 4021 } 4022 4023 // ----- Add the path 4024 if ($p_path != '') { 4025 $p_entry['filename'] = $p_path."/".$p_entry['filename']; 4026 } 4027 4028 // ----- Check a base_dir_restriction 4029 if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { 4030 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Check the extract directory restriction"); 4031 $v_inclusion 4032 = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], 4033 $p_entry['filename']); 4034 if ($v_inclusion == 0) { 4035 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction"); 4036 4037 PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, 4038 "Filename '".$p_entry['filename']."' is " 3587 4039 ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); 3588 4040 3589 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());3590 return PclZip::errorCode();3591 }3592 }3593 3594 // ----- Look for pre-extract callback3595 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {3596 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction");3597 3598 // ----- Generate a local information3599 $v_local_header = array();3600 $this->privConvertHeader2FileInfo($p_entry, $v_local_header);3601 3602 // ----- Call the callback3603 // Here I do not use call_user_func() because I need to send a reference to the3604 // header.3605 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');3606 if ($v_result == 0) {3607 // ----- Change the file status3608 $p_entry['status'] = "skipped";3609 $v_result = 1;3610 }3611 3612 // ----- Look for abort result3613 if ($v_result == 2) {3614 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");3615 // ----- This status is internal and will be changed in 'skipped'3616 $p_entry['status'] = "aborted";3617 $v_result = PCLZIP_ERR_USER_ABORTED;3618 }3619 3620 // ----- Update the informations3621 // Only some fields can be modified3622 $p_entry['filename'] = $v_local_header['filename'];3623 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");3624 }3625 3626 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");3627 3628 // ----- Look if extraction should be done3629 if ($p_entry['status'] == 'ok') {3630 3631 // ----- Look for specific actions while the file exist3632 if (file_exists($p_entry['filename']))3633 {3634 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_entry['filename']."' already exists");3635 3636 // ----- Look if file is a directory3637 if (is_dir($p_entry['filename']))3638 {3639 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is a directory");3640 3641 // ----- Change the file status3642 $p_entry['status'] = "already_a_directory";3643 3644 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR3645 // For historical reason first PclZip implementation does not stop3646 // when this kind of error occurs.3647 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))3648 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {3649 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");3650 3651 PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,3652 "Filename '".$p_entry['filename']."' is "4041 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4042 return PclZip::errorCode(); 4043 } 4044 } 4045 4046 // ----- Look for pre-extract callback 4047 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { 4048 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction"); 4049 4050 // ----- Generate a local information 4051 $v_local_header = array(); 4052 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 4053 4054 // ----- Call the callback 4055 // Here I do not use call_user_func() because I need to send a reference to the 4056 // header. 4057 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); 4058 if ($v_result == 0) { 4059 // ----- Change the file status 4060 $p_entry['status'] = "skipped"; 4061 $v_result = 1; 4062 } 4063 4064 // ----- Look for abort result 4065 if ($v_result == 2) { 4066 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); 4067 // ----- This status is internal and will be changed in 'skipped' 4068 $p_entry['status'] = "aborted"; 4069 $v_result = PCLZIP_ERR_USER_ABORTED; 4070 } 4071 4072 // ----- Update the informations 4073 // Only some fields can be modified 4074 $p_entry['filename'] = $v_local_header['filename']; 4075 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'"); 4076 } 4077 4078 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'"); 4079 4080 // ----- Look if extraction should be done 4081 if ($p_entry['status'] == 'ok') { 4082 4083 // ----- Look for specific actions while the file exist 4084 if (file_exists($p_entry['filename'])) 4085 { 4086 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_entry['filename']."' already exists"); 4087 4088 // ----- Look if file is a directory 4089 if (is_dir($p_entry['filename'])) 4090 { 4091 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is a directory"); 4092 4093 // ----- Change the file status 4094 $p_entry['status'] = "already_a_directory"; 4095 4096 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 4097 // For historical reason first PclZip implementation does not stop 4098 // when this kind of error occurs. 4099 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 4100 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 4101 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 4102 4103 PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, 4104 "Filename '".$p_entry['filename']."' is " 3653 4105 ."already used by an existing directory"); 3654 4106 3655 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());3656 return PclZip::errorCode();3657 }3658 }3659 // ----- Look if file is write protected3660 else if (!is_writeable($p_entry['filename']))3661 {3662 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is write protected");3663 3664 // ----- Change the file status3665 $p_entry['status'] = "write_protected";3666 3667 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR3668 // For historical reason first PclZip implementation does not stop3669 // when this kind of error occurs.3670 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))3671 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {3672 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");3673 3674 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,3675 "Filename '".$p_entry['filename']."' exists "4107 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4108 return PclZip::errorCode(); 4109 } 4110 } 4111 // ----- Look if file is write protected 4112 else if (!is_writeable($p_entry['filename'])) 4113 { 4114 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is write protected"); 4115 4116 // ----- Change the file status 4117 $p_entry['status'] = "write_protected"; 4118 4119 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 4120 // For historical reason first PclZip implementation does not stop 4121 // when this kind of error occurs. 4122 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 4123 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 4124 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 4125 4126 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 4127 "Filename '".$p_entry['filename']."' exists " 3676 4128 ."and is write protected"); 3677 4129 3678 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3679 return PclZip::errorCode(); 3680 } 3681 } 3682 3683 // ----- Look if the extracted file is older 3684 else if (filemtime($p_entry['filename']) > $p_entry['mtime']) 3685 { 3686 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is newer (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")"); 3687 // ----- Change the file status 3688 if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) 3689 && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { 3690 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_REPLACE_NEWER is selected, file will be replaced"); 4130 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4131 return PclZip::errorCode(); 4132 } 4133 } 4134 4135 // ----- Look if the extracted file is older 4136 else if (filemtime($p_entry['filename']) > $p_entry['mtime']) 4137 { 4138 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is newer (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")"); 4139 // ----- Change the file status 4140 if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) 4141 && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { 4142 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_REPLACE_NEWER is selected, file will be replaced"); 4143 } 4144 else { 4145 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be replaced"); 4146 $p_entry['status'] = "newer_exist"; 4147 4148 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 4149 // For historical reason first PclZip implementation does not stop 4150 // when this kind of error occurs. 4151 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 4152 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 4153 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 4154 4155 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 4156 "Newer version of '".$p_entry['filename']."' exists " 4157 ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); 4158 4159 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4160 return PclZip::errorCode(); 4161 } 4162 } 4163 } 4164 else { 4165 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is older than the extrated one - will be replaced by the extracted one (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")"); 4166 } 4167 } 4168 4169 // ----- Check the directory availability and create it if necessary 4170 else { 4171 if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) 4172 $v_dir_to_check = $p_entry['filename']; 4173 else if (!strstr($p_entry['filename'], "/")) 4174 $v_dir_to_check = ""; 4175 else 4176 $v_dir_to_check = dirname($p_entry['filename']); 4177 4178 if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { 4179 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '".$p_entry['filename']."'"); 4180 4181 // ----- Change the file status 4182 $p_entry['status'] = "path_creation_fail"; 4183 4184 // ----- Return 4185 ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4186 //return $v_result; 4187 $v_result = 1; 4188 } 4189 } 4190 } 4191 4192 // ----- Look if extraction should be done 4193 if ($p_entry['status'] == 'ok') { 4194 4195 // ----- Do the extraction (if not a folder) 4196 if (!(($p_entry['external']&0x00000010)==0x00000010)) 4197 { 4198 // ----- Look for not compressed file 4199 if ($p_entry['compression'] == 0) { 4200 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); 4201 4202 // ----- Opening destination file 4203 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) 4204 { 4205 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); 4206 4207 // ----- Change the file status 4208 $p_entry['status'] = "write_error"; 4209 4210 // ----- Return 4211 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4212 return $v_result; 4213 } 4214 4215 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read '".$p_entry['size']."' bytes"); 4216 4217 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks 4218 $v_size = $p_entry['compressed_size']; 4219 while ($v_size != 0) 4220 { 4221 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 4222 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes"); 4223 $v_buffer = @fread($this->zip_fd, $v_read_size); 4224 /* Try to speed up the code 4225 $v_binary_data = pack('a'.$v_read_size, $v_buffer); 4226 @fwrite($v_dest_file, $v_binary_data, $v_read_size); 4227 */ 4228 @fwrite($v_dest_file, $v_buffer, $v_read_size); 4229 $v_size -= $v_read_size; 4230 } 4231 4232 // ----- Closing the destination file 4233 fclose($v_dest_file); 4234 4235 // ----- Change the file mtime 4236 touch($p_entry['filename'], $p_entry['mtime']); 4237 4238 3691 4239 } 3692 4240 else { 3693 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be replaced"); 3694 $p_entry['status'] = "newer_exist"; 3695 3696 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 3697 // For historical reason first PclZip implementation does not stop 3698 // when this kind of error occurs. 3699 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 3700 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 3701 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 3702 3703 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 3704 "Newer version of '".$p_entry['filename']."' exists " 3705 ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); 3706 3707 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3708 return PclZip::errorCode(); 3709 } 3710 } 3711 } 3712 else { 3713 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is older than the extrated one - will be replaced by the extracted one (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")"); 3714 } 3715 } 3716 3717 // ----- Check the directory availability and create it if necessary 3718 else { 3719 if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) 3720 $v_dir_to_check = $p_entry['filename']; 3721 else if (!strstr($p_entry['filename'], "/")) 3722 $v_dir_to_check = ""; 3723 else 3724 $v_dir_to_check = dirname($p_entry['filename']); 3725 3726 if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { 3727 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '".$p_entry['filename']."'"); 3728 3729 // ----- Change the file status 3730 $p_entry['status'] = "path_creation_fail"; 3731 3732 // ----- Return 3733 ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3734 //return $v_result; 3735 $v_result = 1; 3736 } 3737 } 3738 } 3739 3740 // ----- Look if extraction should be done 3741 if ($p_entry['status'] == 'ok') { 3742 3743 // ----- Do the extraction (if not a folder) 3744 if (!(($p_entry['external']&0x00000010)==0x00000010)) 3745 { 3746 // ----- Look for not compressed file 3747 if ($p_entry['compression'] == 0) { 3748 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); 3749 4241 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (Compression method ".$p_entry['compression'].")"); 4242 // ----- TBC 4243 // Need to be finished 4244 if (($p_entry['flag'] & 1) == 1) { 4245 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File is encrypted"); 4246 /* 4247 // ----- Read the encryption header 4248 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read 12 encryption header bytes"); 4249 $v_encryption_header = @fread($this->zip_fd, 12); 4250 4251 // ----- Read the encrypted & compressed file in a buffer 4252 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".($p_entry['compressed_size']-12)."' compressed & encrypted bytes"); 4253 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']-12); 4254 4255 // ----- Decrypt the buffer 4256 $this->privDecrypt($v_encryption_header, $v_buffer, 4257 $p_entry['compressed_size']-12, $p_entry['crc']); 4258 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Buffer is '".$v_buffer."'"); 4259 */ 4260 } 4261 else { 4262 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".$p_entry['compressed_size']."' compressed bytes"); 4263 // ----- Read the compressed file in a buffer (one shot) 4264 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 4265 } 4266 4267 // ----- Decompress the file 4268 $v_file_content = @gzinflate($v_buffer); 4269 unset($v_buffer); 4270 if ($v_file_content === FALSE) { 4271 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to inflate compressed file"); 4272 4273 // ----- Change the file status 4274 // TBC 4275 $p_entry['status'] = "error"; 4276 4277 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4278 return $v_result; 4279 } 4280 3750 4281 // ----- Opening destination file 3751 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) 3752 { 3753 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); 3754 3755 // ----- Change the file status 3756 $p_entry['status'] = "write_error"; 3757 3758 // ----- Return 3759 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3760 return $v_result; 3761 } 3762 3763 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read '".$p_entry['size']."' bytes"); 3764 3765 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks 3766 $v_size = $p_entry['compressed_size']; 3767 while ($v_size != 0) 3768 { 3769 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 3770 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes"); 3771 $v_buffer = @fread($this->zip_fd, $v_read_size); 3772 /* Try to speed up the code 3773 $v_binary_data = pack('a'.$v_read_size, $v_buffer); 3774 @fwrite($v_dest_file, $v_binary_data, $v_read_size); 3775 */ 3776 @fwrite($v_dest_file, $v_buffer, $v_read_size); 3777 $v_size -= $v_read_size; 3778 } 3779 3780 // ----- Closing the destination file 3781 fclose($v_dest_file); 3782 3783 // ----- Change the file mtime 3784 touch($p_entry['filename'], $p_entry['mtime']); 3785 3786 3787 } 3788 else { 3789 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (Compression method ".$p_entry['compression'].")"); 3790 // ----- TBC 3791 // Need to be finished 3792 if (($p_entry['flag'] & 1) == 1) { 3793 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File is encrypted"); 3794 /* 3795 // ----- Read the encryption header 3796 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read 12 encryption header bytes"); 3797 $v_encryption_header = @fread($this->zip_fd, 12); 3798 3799 // ----- Read the encrypted & compressed file in a buffer 3800 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".($p_entry['compressed_size']-12)."' compressed & encrypted bytes"); 3801 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']-12); 3802 3803 // ----- Decrypt the buffer 3804 $this->privDecrypt($v_encryption_header, $v_buffer, 3805 $p_entry['compressed_size']-12, $p_entry['crc']); 3806 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Buffer is '".$v_buffer."'"); 3807 */ 3808 } 3809 else { 3810 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".$p_entry['compressed_size']."' compressed bytes"); 3811 // ----- Read the compressed file in a buffer (one shot) 3812 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 3813 } 3814 3815 // ----- Decompress the file 3816 $v_file_content = @gzinflate($v_buffer); 3817 unset($v_buffer); 3818 if ($v_file_content === FALSE) { 3819 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to inflate compressed file"); 3820 3821 // ----- Change the file status 3822 // TBC 3823 $p_entry['status'] = "error"; 3824 3825 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3826 return $v_result; 3827 } 3828 3829 // ----- Opening destination file 3830 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { 3831 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); 3832 3833 // ----- Change the file status 3834 $p_entry['status'] = "write_error"; 3835 3836 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3837 return $v_result; 3838 } 3839 3840 // ----- Write the uncompressed data 3841 @fwrite($v_dest_file, $v_file_content, $p_entry['size']); 3842 unset($v_file_content); 3843 3844 // ----- Closing the destination file 3845 @fclose($v_dest_file); 3846 3847 // ----- Change the file mtime 3848 @touch($p_entry['filename'], $p_entry['mtime']); 3849 } 3850 3851 // ----- Look for chmod option 3852 if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { 3853 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "chmod option activated '".$p_options[PCLZIP_OPT_SET_CHMOD]."'"); 3854 3855 // ----- Change the mode of the file 3856 @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); 3857 } 3858 3859 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); 3860 } 3861 } 4282 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { 4283 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); 4284 4285 // ----- Change the file status 4286 $p_entry['status'] = "write_error"; 4287 4288 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4289 return $v_result; 4290 } 4291 4292 // ----- Write the uncompressed data 4293 @fwrite($v_dest_file, $v_file_content, $p_entry['size']); 4294 unset($v_file_content); 4295 4296 // ----- Closing the destination file 4297 @fclose($v_dest_file); 4298 4299 // ----- Change the file mtime 4300 @touch($p_entry['filename'], $p_entry['mtime']); 4301 } 4302 4303 // ----- Look for chmod option 4304 if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { 4305 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "chmod option activated '".$p_options[PCLZIP_OPT_SET_CHMOD]."'"); 4306 4307 // ----- Change the mode of the file 4308 @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); 4309 } 4310 4311 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); 4312 } 4313 } 3862 4314 3863 4315 // ----- Change abort status 3864 4316 if ($p_entry['status'] == "aborted") { 3865 $p_entry['status'] = "skipped";3866 } 3867 3868 // ----- Look for post-extract callback3869 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {3870 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction");3871 3872 // ----- Generate a local information3873 $v_local_header = array();3874 $this->privConvertHeader2FileInfo($p_entry, $v_local_header);3875 3876 // ----- Call the callback3877 // Here I do not use call_user_func() because I need to send a reference to the3878 // header.3879 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');3880 3881 // ----- Look for abort result3882 if ($v_result == 2) {3883 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");3884 $v_result = PCLZIP_ERR_USER_ABORTED;3885 }3886 }3887 3888 // ----- Return3889 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3890 return $v_result;4317 $p_entry['status'] = "skipped"; 4318 } 4319 4320 // ----- Look for post-extract callback 4321 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { 4322 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction"); 4323 4324 // ----- Generate a local information 4325 $v_local_header = array(); 4326 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 4327 4328 // ----- Call the callback 4329 // Here I do not use call_user_func() because I need to send a reference to the 4330 // header. 4331 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); 4332 4333 // ----- Look for abort result 4334 if ($v_result == 2) { 4335 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); 4336 $v_result = PCLZIP_ERR_USER_ABORTED; 4337 } 4338 } 4339 4340 // ----- Return 4341 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4342 return $v_result; 3891 4343 } 3892 4344 // -------------------------------------------------------------------------------- … … 3900 4352 function privExtractFileInOutput(&$p_entry, &$p_options) 3901 4353 { 3902 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileInOutput', "");3903 $v_result=1;3904 3905 // ----- Read the file header3906 if (($v_result = $this->privReadFileHeader($v_header)) != 1) {3907 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3908 return $v_result;3909 }3910 3911 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");3912 3913 // ----- Check that the file header is coherent with $p_entry info3914 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {3915 // TBC3916 }3917 3918 // ----- Look for pre-extract callback3919 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {3920 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction");3921 3922 // ----- Generate a local information3923 $v_local_header = array();3924 $this->privConvertHeader2FileInfo($p_entry, $v_local_header);3925 3926 // ----- Call the callback3927 // Here I do not use call_user_func() because I need to send a reference to the3928 // header.3929 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');3930 if ($v_result == 0) {3931 // ----- Change the file status3932 $p_entry['status'] = "skipped";3933 $v_result = 1;3934 }3935 3936 // ----- Look for abort result3937 if ($v_result == 2) {3938 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");3939 // ----- This status is internal and will be changed in 'skipped'3940 $p_entry['status'] = "aborted";3941 $v_result = PCLZIP_ERR_USER_ABORTED;3942 }3943 3944 // ----- Update the informations3945 // Only some fields can be modified3946 $p_entry['filename'] = $v_local_header['filename'];3947 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");3948 }3949 3950 // ----- Trace3951 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");3952 3953 // ----- Look if extraction should be done3954 if ($p_entry['status'] == 'ok') {3955 3956 // ----- Do the extraction (if not a folder)3957 if (!(($p_entry['external']&0x00000010)==0x00000010)) {3958 // ----- Look for not compressed file3959 if ($p_entry['compressed_size'] == $p_entry['size']) {3960 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");3961 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes");3962 3963 // ----- Read the file in a buffer (one shot)3964 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);3965 3966 // ----- Send the file to the output3967 echo $v_buffer;3968 unset($v_buffer);3969 }3970 else {3971 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file");3972 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Reading '".$p_entry['size']."' bytes");3973 3974 // ----- Read the compressed file in a buffer (one shot)3975 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);3976 3977 // ----- Decompress the file3978 $v_file_content = gzinflate($v_buffer);3979 unset($v_buffer);3980 3981 // ----- Send the file to the output3982 echo $v_file_content;3983 unset($v_file_content);3984 }3985 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");3986 }3987 }4354 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileInOutput', ""); 4355 $v_result=1; 4356 4357 // ----- Read the file header 4358 if (($v_result = $this->privReadFileHeader($v_header)) != 1) { 4359 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4360 return $v_result; 4361 } 4362 4363 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); 4364 4365 // ----- Check that the file header is coherent with $p_entry info 4366 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { 4367 // TBC 4368 } 4369 4370 // ----- Look for pre-extract callback 4371 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { 4372 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction"); 4373 4374 // ----- Generate a local information 4375 $v_local_header = array(); 4376 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 4377 4378 // ----- Call the callback 4379 // Here I do not use call_user_func() because I need to send a reference to the 4380 // header. 4381 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); 4382 if ($v_result == 0) { 4383 // ----- Change the file status 4384 $p_entry['status'] = "skipped"; 4385 $v_result = 1; 4386 } 4387 4388 // ----- Look for abort result 4389 if ($v_result == 2) { 4390 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); 4391 // ----- This status is internal and will be changed in 'skipped' 4392 $p_entry['status'] = "aborted"; 4393 $v_result = PCLZIP_ERR_USER_ABORTED; 4394 } 4395 4396 // ----- Update the informations 4397 // Only some fields can be modified 4398 $p_entry['filename'] = $v_local_header['filename']; 4399 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'"); 4400 } 4401 4402 // ----- Trace 4403 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'"); 4404 4405 // ----- Look if extraction should be done 4406 if ($p_entry['status'] == 'ok') { 4407 4408 // ----- Do the extraction (if not a folder) 4409 if (!(($p_entry['external']&0x00000010)==0x00000010)) { 4410 // ----- Look for not compressed file 4411 if ($p_entry['compressed_size'] == $p_entry['size']) { 4412 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); 4413 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes"); 4414 4415 // ----- Read the file in a buffer (one shot) 4416 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 4417 4418 // ----- Send the file to the output 4419 echo $v_buffer; 4420 unset($v_buffer); 4421 } 4422 else { 4423 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file"); 4424 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Reading '".$p_entry['size']."' bytes"); 4425 4426 // ----- Read the compressed file in a buffer (one shot) 4427 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 4428 4429 // ----- Decompress the file 4430 $v_file_content = gzinflate($v_buffer); 4431 unset($v_buffer); 4432 4433 // ----- Send the file to the output 4434 echo $v_file_content; 4435 unset($v_file_content); 4436 } 4437 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); 4438 } 4439 } 3988 4440 3989 4441 // ----- Change abort status 3990 4442 if ($p_entry['status'] == "aborted") { 3991 $p_entry['status'] = "skipped";3992 } 3993 3994 // ----- Look for post-extract callback3995 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {3996 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction");3997 3998 // ----- Generate a local information3999 $v_local_header = array();4000 $this->privConvertHeader2FileInfo($p_entry, $v_local_header);4001 4002 // ----- Call the callback4003 // Here I do not use call_user_func() because I need to send a reference to the4004 // header.4005 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');4006 4007 // ----- Look for abort result4008 if ($v_result == 2) {4009 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");4010 $v_result = PCLZIP_ERR_USER_ABORTED;4011 }4012 }4013 4014 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4015 return $v_result;4443 $p_entry['status'] = "skipped"; 4444 } 4445 4446 // ----- Look for post-extract callback 4447 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { 4448 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction"); 4449 4450 // ----- Generate a local information 4451 $v_local_header = array(); 4452 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 4453 4454 // ----- Call the callback 4455 // Here I do not use call_user_func() because I need to send a reference to the 4456 // header. 4457 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); 4458 4459 // ----- Look for abort result 4460 if ($v_result == 2) { 4461 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); 4462 $v_result = PCLZIP_ERR_USER_ABORTED; 4463 } 4464 } 4465 4466 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4467 return $v_result; 4016 4468 } 4017 4469 // -------------------------------------------------------------------------------- … … 4025 4477 function privExtractFileAsString(&$p_entry, &$p_string) 4026 4478 { 4027 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileAsString', "p_entry['filename']='".$p_entry['filename']."'");4028 $v_result=1;4029 4030 // ----- Read the file header4031 $v_header = array();4032 if (($v_result = $this->privReadFileHeader($v_header)) != 1)4033 {4034 // ----- Return4035 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4036 return $v_result;4037 }4038 4039 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");4040 4041 // ----- Check that the file header is coherent with $p_entry info4042 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {4043 // TBC4044 }4045 4046 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file in string (with path) '".$p_entry['filename']."', size '$v_header[size]'");4047 4048 // ----- Do the extraction (if not a folder)4049 if (!(($p_entry['external']&0x00000010)==0x00000010))4050 {4051 // ----- Look for not compressed file4052 // if ($p_entry['compressed_size'] == $p_entry['size'])4053 if ($p_entry['compression'] == 0) {4054 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");4055 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes");4056 4057 // ----- Reading the file4058 $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);4059 }4060 else {4061 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (compression method '".$p_entry['compression']."')");4062 4063 // ----- Reading the file4064 $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);4065 4066 // ----- Decompress the file4067 if (($p_string = @gzinflate($v_data)) === FALSE) {4068 // TBC4069 }4070 }4071 4072 // ----- Trace4073 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");4074 }4075 else {4076 // TBC : error : can not extract a folder in a string4077 }4078 4079 // ----- Return4080 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4081 return $v_result;4479 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileAsString', "p_entry['filename']='".$p_entry['filename']."'"); 4480 $v_result=1; 4481 4482 // ----- Read the file header 4483 $v_header = array(); 4484 if (($v_result = $this->privReadFileHeader($v_header)) != 1) 4485 { 4486 // ----- Return 4487 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4488 return $v_result; 4489 } 4490 4491 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); 4492 4493 // ----- Check that the file header is coherent with $p_entry info 4494 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { 4495 // TBC 4496 } 4497 4498 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file in string (with path) '".$p_entry['filename']."', size '$v_header[size]'"); 4499 4500 // ----- Do the extraction (if not a folder) 4501 if (!(($p_entry['external']&0x00000010)==0x00000010)) 4502 { 4503 // ----- Look for not compressed file 4504 // if ($p_entry['compressed_size'] == $p_entry['size']) 4505 if ($p_entry['compression'] == 0) { 4506 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); 4507 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes"); 4508 4509 // ----- Reading the file 4510 $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); 4511 } 4512 else { 4513 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (compression method '".$p_entry['compression']."')"); 4514 4515 // ----- Reading the file 4516 $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); 4517 4518 // ----- Decompress the file 4519 if (($p_string = @gzinflate($v_data)) === FALSE) { 4520 // TBC 4521 } 4522 } 4523 4524 // ----- Trace 4525 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); 4526 } 4527 else { 4528 // TBC : error : can not extract a folder in a string 4529 } 4530 4531 // ----- Return 4532 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4533 return $v_result; 4082 4534 } 4083 4535 // -------------------------------------------------------------------------------- … … 4091 4543 function privReadFileHeader(&$p_header) 4092 4544 { 4093 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadFileHeader", ""); 4094 $v_result=1; 4095 4096 // ----- Read the 4 bytes signature 4097 $v_binary_data = @fread($this->zip_fd, 4); 4098 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); 4099 $v_data = unpack('Vid', $v_binary_data); 4100 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); 4101 4102 // ----- Check signature 4103 if ($v_data['id'] != 0x04034b50) 4104 { 4105 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid File header"); 4106 4107 // ----- Error log 4108 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); 4109 4110 // ----- Return 4111 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4112 return PclZip::errorCode(); 4113 } 4114 4115 // ----- Read the first 42 bytes of the header 4116 $v_binary_data = fread($this->zip_fd, 26); 4117 4118 // ----- Look for invalid block size 4119 if (strlen($v_binary_data) != 26) 4120 { 4121 $p_header['filename'] = ""; 4122 $p_header['status'] = "invalid_header"; 4123 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data)); 4124 4125 // ----- Error log 4126 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); 4127 4128 // ----- Return 4129 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4130 return PclZip::errorCode(); 4131 } 4132 4133 // ----- Extract the values 4134 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header : '".$v_binary_data."'"); 4135 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header (Hex) : '".bin2hex($v_binary_data)."'"); 4136 $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); 4137 4138 // ----- Get filename 4139 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "File name length : ".$v_data['filename_len']); 4140 $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); 4141 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename : \''.$p_header['filename'].'\''); 4142 4143 // ----- Get extra_fields 4144 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extra field length : ".$v_data['extra_len']); 4145 if ($v_data['extra_len'] != 0) { 4146 $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); 4147 } 4148 else { 4149 $p_header['extra'] = ''; 4150 } 4151 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Extra field : \''.bin2hex($p_header['extra']).'\''); 4152 4153 // ----- Extract properties 4154 $p_header['version_extracted'] = $v_data['version']; 4155 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : ('.$p_header['version_extracted'].') \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\''); 4156 $p_header['compression'] = $v_data['compression']; 4157 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compression method : \''.$p_header['compression'].'\''); 4158 $p_header['size'] = $v_data['size']; 4159 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_header['size'].'\''); 4160 $p_header['compressed_size'] = $v_data['compressed_size']; 4161 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_header['compressed_size'].'\''); 4162 $p_header['crc'] = $v_data['crc']; 4163 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); 4164 $p_header['flag'] = $v_data['flag']; 4165 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag : \''.$p_header['flag'].'\''); 4166 $p_header['filename_len'] = $v_data['filename_len']; 4167 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename_len : \''.$p_header['filename_len'].'\''); 4168 4169 // ----- Recuperate date in UNIX format 4170 $p_header['mdate'] = $v_data['mdate']; 4171 $p_header['mtime'] = $v_data['mtime']; 4172 if ($p_header['mdate'] && $p_header['mtime']) 4173 { 4174 // ----- Extract time 4175 $v_hour = ($p_header['mtime'] & 0xF800) >> 11; 4176 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; 4177 $v_seconde = ($p_header['mtime'] & 0x001F)*2; 4178 4179 // ----- Extract date 4180 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; 4181 $v_month = ($p_header['mdate'] & 0x01E0) >> 5; 4182 $v_day = $p_header['mdate'] & 0x001F; 4183 4184 // ----- Get UNIX date format 4185 $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 4186 4187 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4188 } 4189 else 4190 { 4191 $p_header['mtime'] = time(); 4192 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4193 } 4194 4195 // TBC 4196 //for(reset($v_data); $key = key($v_data); next($v_data)) { 4197 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Attribut[$key] = ".$v_data[$key]); 4198 //} 4199 4200 // ----- Set the stored filename 4201 $p_header['stored_filename'] = $p_header['filename']; 4202 4203 // ----- Set the status field 4204 $p_header['status'] = "ok"; 4205 4206 // ----- Return 4207 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4208 return $v_result; 4545 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadFileHeader", ""); 4546 $v_result=1; 4547 4548 // ----- Read the 4 bytes signature 4549 $v_binary_data = @fread($this->zip_fd, 4); 4550 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); 4551 $v_data = unpack('Vid', $v_binary_data); 4552 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); 4553 4554 // ----- Check signature 4555 if ($v_data['id'] != 0x04034b50) 4556 { 4557 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid File header"); 4558 4559 // ----- Error log 4560 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); 4561 4562 // ----- Return 4563 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4564 return PclZip::errorCode(); 4565 } 4566 4567 // ----- Read the first 42 bytes of the header 4568 $v_binary_data = fread($this->zip_fd, 26); 4569 4570 // ----- Look for invalid block size 4571 if (strlen($v_binary_data) != 26) 4572 { 4573 $p_header['filename'] = ""; 4574 $p_header['status'] = "invalid_header"; 4575 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data)); 4576 4577 // ----- Error log 4578 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); 4579 4580 // ----- Return 4581 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4582 return PclZip::errorCode(); 4583 } 4584 4585 // ----- Extract the values 4586 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header : '".$v_binary_data."'"); 4587 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header (Hex) : '".bin2hex($v_binary_data)."'"); 4588 $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); 4589 4590 // ----- Get filename 4591 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "File name length : ".$v_data['filename_len']); 4592 $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); 4593 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename : \''.$p_header['filename'].'\''); 4594 4595 // ----- Get extra_fields 4596 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extra field length : ".$v_data['extra_len']); 4597 if ($v_data['extra_len'] != 0) { 4598 $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); 4599 } 4600 else { 4601 $p_header['extra'] = ''; 4602 } 4603 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Extra field : \''.bin2hex($p_header['extra']).'\''); 4604 4605 // ----- Extract properties 4606 $p_header['version_extracted'] = $v_data['version']; 4607 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : ('.$p_header['version_extracted'].') \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\''); 4608 $p_header['compression'] = $v_data['compression']; 4609 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compression method : \''.$p_header['compression'].'\''); 4610 $p_header['size'] = $v_data['size']; 4611 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_header['size'].'\''); 4612 $p_header['compressed_size'] = $v_data['compressed_size']; 4613 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_header['compressed_size'].'\''); 4614 $p_header['crc'] = $v_data['crc']; 4615 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); 4616 $p_header['flag'] = $v_data['flag']; 4617 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag : \''.$p_header['flag'].'\''); 4618 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag bit 11 (from right) : \''.($p_header['flag']&0x0400).'\''); 4619 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag bit 11 (from left) : \''.($p_header['flag']&0x0020).'\''); 4620 $p_header['filename_len'] = $v_data['filename_len']; 4621 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename_len : \''.$p_header['filename_len'].'\''); 4622 4623 // ----- Recuperate date in UNIX format 4624 $p_header['mdate'] = $v_data['mdate']; 4625 $p_header['mtime'] = $v_data['mtime']; 4626 if ($p_header['mdate'] && $p_header['mtime']) 4627 { 4628 // ----- Extract time 4629 $v_hour = ($p_header['mtime'] & 0xF800) >> 11; 4630 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; 4631 $v_seconde = ($p_header['mtime'] & 0x001F)*2; 4632 4633 // ----- Extract date 4634 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; 4635 $v_month = ($p_header['mdate'] & 0x01E0) >> 5; 4636 $v_day = $p_header['mdate'] & 0x001F; 4637 4638 // ----- Get UNIX date format 4639 $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 4640 4641 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4642 } 4643 else 4644 { 4645 $p_header['mtime'] = time(); 4646 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4647 } 4648 4649 // TBC 4650 //for(reset($v_data); $key = key($v_data); next($v_data)) { 4651 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Attribut[$key] = ".$v_data[$key]); 4652 //} 4653 4654 // ----- Set the stored filename 4655 $p_header['stored_filename'] = $p_header['filename']; 4656 4657 // ----- Set the status field 4658 $p_header['status'] = "ok"; 4659 4660 // ----- Return 4661 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4662 return $v_result; 4209 4663 } 4210 4664 // -------------------------------------------------------------------------------- … … 4218 4672 function privReadCentralFileHeader(&$p_header) 4219 4673 { 4220 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadCentralFileHeader", ""); 4221 $v_result=1; 4222 4223 // ----- Read the 4 bytes signature 4224 $v_binary_data = @fread($this->zip_fd, 4); 4225 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); 4226 $v_data = unpack('Vid', $v_binary_data); 4227 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); 4228 4229 // ----- Check signature 4230 if ($v_data['id'] != 0x02014b50) 4231 { 4232 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid Central Dir File signature"); 4233 4234 // ----- Error log 4235 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); 4236 4237 // ----- Return 4238 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4239 return PclZip::errorCode(); 4240 } 4241 4242 // ----- Read the first 42 bytes of the header 4243 $v_binary_data = fread($this->zip_fd, 42); 4244 4245 // ----- Look for invalid block size 4246 if (strlen($v_binary_data) != 42) 4247 { 4248 $p_header['filename'] = ""; 4249 $p_header['status'] = "invalid_header"; 4250 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data)); 4251 4252 // ----- Error log 4253 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); 4254 4255 // ----- Return 4256 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4257 return PclZip::errorCode(); 4258 } 4259 4260 // ----- Extract the values 4261 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header : '".$v_binary_data."'"); 4262 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header (Hex) : '".bin2hex($v_binary_data)."'"); 4263 $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data); 4264 4265 // ----- Get filename 4266 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File name length : ".$p_header['filename_len']); 4267 if ($p_header['filename_len'] != 0) 4268 $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); 4269 else 4270 $p_header['filename'] = ''; 4271 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Filename : \''.$p_header['filename'].'\''); 4272 4273 // ----- Get extra 4274 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Extra length : ".$p_header['extra_len']); 4275 if ($p_header['extra_len'] != 0) 4276 $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); 4277 else 4278 $p_header['extra'] = ''; 4279 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Extra : \''.$p_header['extra'].'\''); 4280 4281 // ----- Get comment 4282 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Comment length : ".$p_header['comment_len']); 4283 if ($p_header['comment_len'] != 0) 4284 $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); 4285 else 4286 $p_header['comment'] = ''; 4287 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Comment : \''.$p_header['comment'].'\''); 4288 4289 // ----- Extract properties 4290 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version : \''.($p_header['version']/10).'.'.($p_header['version']%10).'\''); 4291 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\''); 4292 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Size : \''.$p_header['size'].'\''); 4293 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Compressed Size : \''.$p_header['compressed_size'].'\''); 4294 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); 4295 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Flag : \''.$p_header['flag'].'\''); 4296 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Offset : \''.$p_header['offset'].'\''); 4297 4298 // ----- Recuperate date in UNIX format 4299 if ($p_header['mdate'] && $p_header['mtime']) 4300 { 4301 // ----- Extract time 4302 $v_hour = ($p_header['mtime'] & 0xF800) >> 11; 4303 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; 4304 $v_seconde = ($p_header['mtime'] & 0x001F)*2; 4305 4306 // ----- Extract date 4307 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; 4308 $v_month = ($p_header['mdate'] & 0x01E0) >> 5; 4309 $v_day = $p_header['mdate'] & 0x001F; 4310 4311 // ----- Get UNIX date format 4312 $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 4313 4314 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4315 } 4316 else 4317 { 4318 $p_header['mtime'] = time(); 4319 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4320 } 4321 4322 // ----- Set the stored filename 4323 $p_header['stored_filename'] = $p_header['filename']; 4324 4325 // ----- Set default status to ok 4326 $p_header['status'] = 'ok'; 4327 4328 // ----- Look if it is a directory 4329 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Internal (Hex) : '".sprintf("Ox%04X", $p_header['internal'])."'"); 4330 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "External (Hex) : '".sprintf("Ox%04X", $p_header['external'])."' (".(($p_header['external']&0x00000010)==0x00000010?'is a folder':'is a file').')'); 4331 if (substr($p_header['filename'], -1) == '/') { 4332 //$p_header['external'] = 0x41FF0010; 4333 $p_header['external'] = 0x00000010; 4334 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Force folder external : \''.sprintf("Ox%04X", $p_header['external']).'\''); 4335 } 4336 4337 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Header of filename : \''.$p_header['filename'].'\''); 4338 4339 // ----- Return 4340 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4341 return $v_result; 4674 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadCentralFileHeader", ""); 4675 $v_result=1; 4676 4677 // ----- Read the 4 bytes signature 4678 $v_binary_data = @fread($this->zip_fd, 4); 4679 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); 4680 $v_data = unpack('Vid', $v_binary_data); 4681 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); 4682 4683 // ----- Check signature 4684 if ($v_data['id'] != 0x02014b50) 4685 { 4686 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid Central Dir File signature"); 4687 4688 // ----- Error log 4689 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); 4690 4691 // ----- Return 4692 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4693 return PclZip::errorCode(); 4694 } 4695 4696 // ----- Read the first 42 bytes of the header 4697 $v_binary_data = fread($this->zip_fd, 42); 4698 4699 // ----- Look for invalid block size 4700 if (strlen($v_binary_data) != 42) 4701 { 4702 $p_header['filename'] = ""; 4703 $p_header['status'] = "invalid_header"; 4704 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data)); 4705 4706 // ----- Error log 4707 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); 4708 4709 // ----- Return 4710 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4711 return PclZip::errorCode(); 4712 } 4713 4714 // ----- Extract the values 4715 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header : '".$v_binary_data."'"); 4716 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header (Hex) : '".bin2hex($v_binary_data)."'"); 4717 $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data); 4718 4719 // ----- Get filename 4720 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File name length : ".$p_header['filename_len']); 4721 if ($p_header['filename_len'] != 0) 4722 $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); 4723 else 4724 $p_header['filename'] = ''; 4725 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Filename : \''.$p_header['filename'].'\''); 4726 4727 // ----- Get extra 4728 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Extra length : ".$p_header['extra_len']); 4729 if ($p_header['extra_len'] != 0) 4730 $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); 4731 else 4732 $p_header['extra'] = ''; 4733 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Extra : \''.$p_header['extra'].'\''); 4734 4735 // ----- Get comment 4736 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Comment length : ".$p_header['comment_len']); 4737 if ($p_header['comment_len'] != 0) 4738 $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); 4739 else 4740 $p_header['comment'] = ''; 4741 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Comment : \''.$p_header['comment'].'\''); 4742 4743 // ----- Extract properties 4744 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version : \''.($p_header['version']/10).'.'.($p_header['version']%10).'\''); 4745 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\''); 4746 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Size : \''.$p_header['size'].'\''); 4747 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Compressed Size : \''.$p_header['compressed_size'].'\''); 4748 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); 4749 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Flag : \''.$p_header['flag'].'\''); 4750 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Offset : \''.$p_header['offset'].'\''); 4751 4752 // ----- Recuperate date in UNIX format 4753 //if ($p_header['mdate'] && $p_header['mtime']) 4754 // TBC : bug : this was ignoring time with 0/0/0 4755 if (1) 4756 { 4757 // ----- Extract time 4758 $v_hour = ($p_header['mtime'] & 0xF800) >> 11; 4759 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; 4760 $v_seconde = ($p_header['mtime'] & 0x001F)*2; 4761 4762 // ----- Extract date 4763 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; 4764 $v_month = ($p_header['mdate'] & 0x01E0) >> 5; 4765 $v_day = $p_header['mdate'] & 0x001F; 4766 4767 // ----- Get UNIX date format 4768 $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 4769 4770 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4771 } 4772 else 4773 { 4774 $p_header['mtime'] = time(); 4775 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4776 } 4777 4778 // ----- Set the stored filename 4779 $p_header['stored_filename'] = $p_header['filename']; 4780 4781 // ----- Set default status to ok 4782 $p_header['status'] = 'ok'; 4783 4784 // ----- Look if it is a directory 4785 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Internal (Hex) : '".sprintf("Ox%04X", $p_header['internal'])."'"); 4786 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "External (Hex) : '".sprintf("Ox%04X", $p_header['external'])."' (".(($p_header['external']&0x00000010)==0x00000010?'is a folder':'is a file').')'); 4787 if (substr($p_header['filename'], -1) == '/') { 4788 //$p_header['external'] = 0x41FF0010; 4789 $p_header['external'] = 0x00000010; 4790 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Force folder external : \''.sprintf("Ox%04X", $p_header['external']).'\''); 4791 } 4792 4793 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Header of filename : \''.$p_header['filename'].'\''); 4794 4795 // ----- Return 4796 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4797 return $v_result; 4342 4798 } 4343 4799 // -------------------------------------------------------------------------------- … … 4353 4809 function privCheckFileHeaders(&$p_local_header, &$p_central_header) 4354 4810 { 4355 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFileHeaders", "");4356 $v_result=1;4811 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFileHeaders", ""); 4812 $v_result=1; 4357 4813 4358 4814 // ----- Check the static values 4359 4815 // TBC 4360 4816 if ($p_local_header['filename'] != $p_central_header['filename']) { 4361 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename" : TBC To Be Completed');4817 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename" : TBC To Be Completed'); 4362 4818 } 4363 4819 if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { 4364 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "version_extracted" : TBC To Be Completed');4820 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "version_extracted" : TBC To Be Completed'); 4365 4821 } 4366 4822 if ($p_local_header['flag'] != $p_central_header['flag']) { 4367 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "flag" : TBC To Be Completed');4823 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "flag" : TBC To Be Completed'); 4368 4824 } 4369 4825 if ($p_local_header['compression'] != $p_central_header['compression']) { 4370 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "compression" : TBC To Be Completed');4826 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "compression" : TBC To Be Completed'); 4371 4827 } 4372 4828 if ($p_local_header['mtime'] != $p_central_header['mtime']) { 4373 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "mtime" : TBC To Be Completed');4829 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "mtime" : TBC To Be Completed'); 4374 4830 } 4375 4831 if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { 4376 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename_len" : TBC To Be Completed');4832 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename_len" : TBC To Be Completed'); 4377 4833 } 4378 4834 4379 4835 // ----- Look for flag bit 3 4380 4836 if (($p_local_header['flag'] & 8) == 8) { 4381 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Purpose bit flag bit 3 set !');4382 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'File size, compression size and crc found in central header');4383 $p_local_header['size'] = $p_central_header['size'];4384 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_local_header['size'].'\'');4385 $p_local_header['compressed_size'] = $p_central_header['compressed_size'];4386 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_local_header['compressed_size'].'\'');4387 $p_local_header['crc'] = $p_central_header['crc'];4388 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_local_header['crc']).'\'');4389 } 4390 4391 // ----- Return4392 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4393 return $v_result;4837 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Purpose bit flag bit 3 set !'); 4838 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'File size, compression size and crc found in central header'); 4839 $p_local_header['size'] = $p_central_header['size']; 4840 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_local_header['size'].'\''); 4841 $p_local_header['compressed_size'] = $p_central_header['compressed_size']; 4842 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_local_header['compressed_size'].'\''); 4843 $p_local_header['crc'] = $p_central_header['crc']; 4844 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_local_header['crc']).'\''); 4845 } 4846 4847 // ----- Return 4848 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4849 return $v_result; 4394 4850 } 4395 4851 // -------------------------------------------------------------------------------- … … 4403 4859 function privReadEndCentralDir(&$p_central_dir) 4404 4860 { 4405 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadEndCentralDir", ""); 4406 $v_result=1; 4407 4408 // ----- Go to the end of the zip file 4409 $v_size = filesize($this->zipname); 4410 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size of the file :$v_size"); 4411 @fseek($this->zip_fd, $v_size); 4412 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position at end of zip file : \''.ftell($this->zip_fd).'\''); 4413 if (@ftell($this->zip_fd) != $v_size) 4414 { 4415 // ----- Error log 4416 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); 4417 4418 // ----- Return 4419 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4420 return PclZip::errorCode(); 4421 } 4422 4423 // ----- First try : look if this is an archive with no commentaries (most of the time) 4424 // in this case the end of central dir is at 22 bytes of the file end 4425 $v_found = 0; 4426 if ($v_size > 26) { 4427 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Look for central dir with no comment'); 4428 @fseek($this->zip_fd, $v_size-22); 4429 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after min central position : \''.ftell($this->zip_fd).'\''); 4430 if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) 4431 { 4432 // ----- Error log 4433 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); 4434 4435 // ----- Return 4436 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4437 return PclZip::errorCode(); 4438 } 4439 4440 // ----- Read for bytes 4441 $v_binary_data = @fread($this->zip_fd, 4); 4442 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); 4443 $v_data = @unpack('Vid', $v_binary_data); 4444 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); 4445 4446 // ----- Check signature 4447 if ($v_data['id'] == 0x06054b50) { 4448 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found central dir at the default position."); 4449 $v_found = 1; 4450 } 4451 4452 $v_pos = ftell($this->zip_fd); 4453 } 4454 4455 // ----- Go back to the maximum possible size of the Central Dir End Record 4456 if (!$v_found) { 4457 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Start extended search of end central dir'); 4458 $v_maximum_size = 65557; // 0xFFFF + 22; 4459 if ($v_maximum_size > $v_size) 4460 $v_maximum_size = $v_size; 4461 @fseek($this->zip_fd, $v_size-$v_maximum_size); 4462 if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) 4463 { 4464 // ----- Error log 4465 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); 4466 4467 // ----- Return 4468 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4469 return PclZip::errorCode(); 4470 } 4471 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after max central position : \''.ftell($this->zip_fd).'\''); 4472 4473 // ----- Read byte per byte in order to find the signature 4474 $v_pos = ftell($this->zip_fd); 4475 $v_bytes = 0x00000000; 4476 while ($v_pos < $v_size) 4477 { 4478 // ----- Read a byte 4479 $v_byte = @fread($this->zip_fd, 1); 4480 4481 // ----- Add the byte 4482 // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number 4483 // Otherwise on systems where we have 64bit integers the check below for the magic number will fail. 4484 $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); 4485 4486 // ----- Compare the bytes 4487 if ($v_bytes == 0x504b0506) 4488 { 4489 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Found End Central Dir signature at position : \''.ftell($this->zip_fd).'\''); 4490 $v_pos++; 4491 break; 4492 } 4493 4494 $v_pos++; 4495 } 4496 4497 // ----- Look if not found end of central dir 4498 if ($v_pos == $v_size) 4499 { 4500 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to find End of Central Dir Record signature"); 4501 4502 // ----- Error log 4503 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); 4504 4505 // ----- Return 4506 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4507 return PclZip::errorCode(); 4508 } 4509 } 4510 4511 // ----- Read the first 18 bytes of the header 4512 $v_binary_data = fread($this->zip_fd, 18); 4513 4514 // ----- Look for invalid block size 4515 if (strlen($v_binary_data) != 18) 4516 { 4517 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); 4518 4519 // ----- Error log 4520 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); 4521 4522 // ----- Return 4523 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4524 return PclZip::errorCode(); 4525 } 4526 4527 // ----- Extract the values 4528 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record : '".$v_binary_data."'"); 4529 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record (Hex) : '".bin2hex($v_binary_data)."'"); 4530 $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); 4531 4532 // ----- Check the global size 4533 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Comment length : ".$v_data['comment_size']); 4534 if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { 4535 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The central dir is not at the end of the archive. Some trailing bytes exists after the archive."); 4861 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadEndCentralDir", ""); 4862 $v_result=1; 4863 4864 // ----- Go to the end of the zip file 4865 $v_size = filesize($this->zipname); 4866 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size of the file :$v_size"); 4867 @fseek($this->zip_fd, $v_size); 4868 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position at end of zip file : \''.ftell($this->zip_fd).'\''); 4869 if (@ftell($this->zip_fd) != $v_size) 4870 { 4871 // ----- Error log 4872 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); 4873 4874 // ----- Return 4875 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4876 return PclZip::errorCode(); 4877 } 4878 4879 // ----- First try : look if this is an archive with no commentaries (most of the time) 4880 // in this case the end of central dir is at 22 bytes of the file end 4881 $v_found = 0; 4882 if ($v_size > 26) { 4883 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Look for central dir with no comment'); 4884 @fseek($this->zip_fd, $v_size-22); 4885 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after min central position : \''.ftell($this->zip_fd).'\''); 4886 if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) 4887 { 4888 // ----- Error log 4889 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); 4890 4891 // ----- Return 4892 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4893 return PclZip::errorCode(); 4894 } 4895 4896 // ----- Read for bytes 4897 $v_binary_data = @fread($this->zip_fd, 4); 4898 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); 4899 $v_data = @unpack('Vid', $v_binary_data); 4900 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); 4901 4902 // ----- Check signature 4903 if ($v_data['id'] == 0x06054b50) { 4904 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found central dir at the default position."); 4905 $v_found = 1; 4906 } 4907 4908 $v_pos = ftell($this->zip_fd); 4909 } 4910 4911 // ----- Go back to the maximum possible size of the Central Dir End Record 4912 if (!$v_found) { 4913 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Start extended search of end central dir'); 4914 $v_maximum_size = 65557; // 0xFFFF + 22; 4915 if ($v_maximum_size > $v_size) 4916 $v_maximum_size = $v_size; 4917 @fseek($this->zip_fd, $v_size-$v_maximum_size); 4918 if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) 4919 { 4920 // ----- Error log 4921 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); 4922 4923 // ----- Return 4924 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4925 return PclZip::errorCode(); 4926 } 4927 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after max central position : \''.ftell($this->zip_fd).'\''); 4928 4929 // ----- Read byte per byte in order to find the signature 4930 $v_pos = ftell($this->zip_fd); 4931 $v_bytes = 0x00000000; 4932 while ($v_pos < $v_size) 4933 { 4934 // ----- Read a byte 4935 $v_byte = @fread($this->zip_fd, 1); 4936 4937 // ----- Add the byte 4938 $v_bytes = ($v_bytes << 8) | Ord($v_byte); 4939 4940 // ----- Compare the bytes 4941 if ($v_bytes == 0x504b0506) 4942 { 4943 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Found End Central Dir signature at position : \''.ftell($this->zip_fd).'\''); 4944 $v_pos++; 4945 break; 4946 } 4947 4948 $v_pos++; 4949 } 4950 4951 // ----- Look if not found end of central dir 4952 if ($v_pos == $v_size) 4953 { 4954 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to find End of Central Dir Record signature"); 4955 4956 // ----- Error log 4957 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); 4958 4959 // ----- Return 4960 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4961 return PclZip::errorCode(); 4962 } 4963 } 4964 4965 // ----- Read the first 18 bytes of the header 4966 $v_binary_data = fread($this->zip_fd, 18); 4967 4968 // ----- Look for invalid block size 4969 if (strlen($v_binary_data) != 18) 4970 { 4971 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); 4972 4973 // ----- Error log 4974 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); 4975 4976 // ----- Return 4977 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4978 return PclZip::errorCode(); 4979 } 4980 4981 // ----- Extract the values 4982 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record : '".$v_binary_data."'"); 4983 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record (Hex) : '".bin2hex($v_binary_data)."'"); 4984 $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); 4985 4986 // ----- Check the global size 4987 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Comment length : ".$v_data['comment_size']); 4988 if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { 4989 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The central dir is not at the end of the archive. Some trailing bytes exists after the archive."); 4536 4990 4537 4991 // ----- Removed in release 2.2 see readme file … … 4540 4994 // While decrypted, zip has training 0 bytes 4541 4995 if (0) { 4542 // ----- Error log4543 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,4544 'The central dir is not at the end of the archive.'4996 // ----- Error log 4997 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 4998 'The central dir is not at the end of the archive.' 4545 4999 .' Some trailing bytes exists after the archive.'); 4546 5000 4547 // ----- Return 4548 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4549 return PclZip::errorCode(); 4550 } 4551 } 4552 4553 // ----- Get comment 4554 if ($v_data['comment_size'] != 0) 4555 $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); 4556 else 4557 $p_central_dir['comment'] = ''; 4558 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment : \''.$p_central_dir['comment'].'\''); 4559 4560 $p_central_dir['entries'] = $v_data['entries']; 4561 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries : \''.$p_central_dir['entries'].'\''); 4562 $p_central_dir['disk_entries'] = $v_data['disk_entries']; 4563 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries for this disk : \''.$p_central_dir['disk_entries'].'\''); 4564 $p_central_dir['offset'] = $v_data['offset']; 4565 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Offset of Central Dir : \''.$p_central_dir['offset'].'\''); 4566 $p_central_dir['size'] = $v_data['size']; 4567 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size of Central Dir : \''.$p_central_dir['size'].'\''); 4568 $p_central_dir['disk'] = $v_data['disk']; 4569 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Disk number : \''.$p_central_dir['disk'].'\''); 4570 $p_central_dir['disk_start'] = $v_data['disk_start']; 4571 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Start disk number : \''.$p_central_dir['disk_start'].'\''); 4572 4573 // TBC 4574 //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) { 4575 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "central_dir[$key] = ".$p_central_dir[$key]); 4576 //} 4577 4578 // ----- Return 4579 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4580 return $v_result; 5001 // ----- Return 5002 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5003 return PclZip::errorCode(); 5004 } 5005 } 5006 5007 // ----- Get comment 5008 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment size : \''.$v_data['comment_size'].'\''); 5009 if ($v_data['comment_size'] != 0) { 5010 $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); 5011 } 5012 else 5013 $p_central_dir['comment'] = ''; 5014 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment : \''.$p_central_dir['comment'].'\''); 5015 5016 $p_central_dir['entries'] = $v_data['entries']; 5017 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries : \''.$p_central_dir['entries'].'\''); 5018 $p_central_dir['disk_entries'] = $v_data['disk_entries']; 5019 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries for this disk : \''.$p_central_dir['disk_entries'].'\''); 5020 $p_central_dir['offset'] = $v_data['offset']; 5021 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Offset of Central Dir : \''.$p_central_dir['offset'].'\''); 5022 $p_central_dir['size'] = $v_data['size']; 5023 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size of Central Dir : \''.$p_central_dir['size'].'\''); 5024 $p_central_dir['disk'] = $v_data['disk']; 5025 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Disk number : \''.$p_central_dir['disk'].'\''); 5026 $p_central_dir['disk_start'] = $v_data['disk_start']; 5027 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Start disk number : \''.$p_central_dir['disk_start'].'\''); 5028 5029 // TBC 5030 //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) { 5031 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "central_dir[$key] = ".$p_central_dir[$key]); 5032 //} 5033 5034 // ----- Return 5035 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5036 return $v_result; 4581 5037 } 4582 5038 // -------------------------------------------------------------------------------- … … 4590 5046 function privDeleteByRule(&$p_result_list, &$p_options) 4591 5047 { 4592 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByRule", "");4593 $v_result=1;4594 $v_list_detail = array();4595 4596 // ----- Open the zip file4597 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");4598 if (($v_result=$this->privOpenFd('rb')) != 1)4599 {4600 // ----- Return4601 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4602 return $v_result;4603 }4604 4605 // ----- Read the central directory informations4606 $v_central_dir = array();4607 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)4608 {4609 $this->privCloseFd();4610 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4611 return $v_result;4612 }4613 4614 // ----- Go to beginning of File4615 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");4616 @rewind($this->zip_fd);4617 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");4618 4619 // ----- Scan all the files4620 // ----- Start at beginning of Central Dir4621 $v_pos_entry = $v_central_dir['offset'];4622 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");4623 @rewind($this->zip_fd);4624 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");4625 if (@fseek($this->zip_fd, $v_pos_entry))4626 {4627 // ----- Close the zip file4628 $this->privCloseFd();4629 4630 // ----- Error log4631 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');4632 4633 // ----- Return4634 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());4635 return PclZip::errorCode();4636 }4637 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");4638 4639 // ----- Read each entry4640 $v_header_list = array();4641 $j_start = 0;4642 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)4643 {4644 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry (index '$i')");4645 4646 // ----- Read the file header4647 $v_header_list[$v_nb_extracted] = array();4648 if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)4649 {4650 // ----- Close the zip file4651 $this->privCloseFd();4652 4653 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4654 return $v_result;4655 }4656 4657 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename (index '$i') : '".$v_header_list[$v_nb_extracted]['stored_filename']."'");4658 4659 // ----- Store the index4660 $v_header_list[$v_nb_extracted]['index'] = $i;4661 4662 // ----- Look for the specific extract rules4663 $v_found = false;4664 4665 // ----- Look for extract by name rule4666 if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))4667 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {4668 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'");4669 4670 // ----- Look if the filename is in the list4671 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {4672 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'");4673 4674 // ----- Look for a directory4675 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {4676 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory");4677 4678 // ----- Look if the directory is in the filename path4679 if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))4680 && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {4681 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path");4682 $v_found = true;4683 }4684 elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */4685 && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {4686 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The entry is the searched directory");4687 $v_found = true;4688 }4689 }4690 // ----- Look for a filename4691 elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {4692 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one.");4693 $v_found = true;4694 }4695 }4696 }4697 4698 // ----- Look for extract by ereg rule4699 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))4700 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {4701 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'");4702 4703 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {4704 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");4705 $v_found = true;4706 }4707 }4708 4709 // ----- Look for extract by preg rule4710 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))4711 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {4712 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'");4713 4714 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {4715 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");4716 $v_found = true;4717 }4718 }4719 4720 // ----- Look for extract by index rule4721 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))4722 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {4723 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'");4724 4725 // ----- Look if the index is in the list4726 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {4727 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]");4728 4729 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {4730 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");4731 $v_found = true;4732 }4733 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {4734 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop");4735 $j_start = $j+1;4736 }4737 4738 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {4739 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop");4740 break;4741 }4742 }4743 }4744 else {4745 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "No argument mean remove all file");4746 $v_found = true;4747 }4748 4749 // ----- Look for deletion4750 if ($v_found)4751 {4752 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' need to be deleted");4753 unset($v_header_list[$v_nb_extracted]);4754 }4755 else4756 {4757 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' will not be deleted");4758 $v_nb_extracted++;4759 }4760 }4761 4762 // ----- Look if something need to be deleted4763 if ($v_nb_extracted > 0) {4764 4765 // ----- Creates a temporay file4766 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';4767 4768 // ----- Creates a temporary zip archive4769 $v_temp_zip = new PclZip($v_zip_temp_name);4770 4771 // ----- Open the temporary zip file in write mode4772 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary write mode");4773 if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {4774 $this->privCloseFd();4775 4776 // ----- Return4777 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4778 return $v_result;4779 }4780 4781 // ----- Look which file need to be kept4782 for ($i=0; $i<sizeof($v_header_list); $i++) {4783 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Keep entry index '$i' : '".$v_header_list[$i]['filename']."'");4784 4785 // ----- Calculate the position of the header4786 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset='". $v_header_list[$i]['offset']."'");4787 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");4788 @rewind($this->zip_fd);4789 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");4790 if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {4791 // ----- Close the zip file4792 $this->privCloseFd();4793 $v_temp_zip->privCloseFd();4794 @unlink($v_zip_temp_name);4795 4796 // ----- Error log4797 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');4798 4799 // ----- Return4800 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());4801 return PclZip::errorCode();4802 }4803 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");4804 4805 // ----- Read the file header4806 $v_local_header = array();4807 if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {4808 // ----- Close the zip file4809 $this->privCloseFd();4810 $v_temp_zip->privCloseFd();4811 @unlink($v_zip_temp_name);4812 4813 // ----- Return4814 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4815 return $v_result;4816 }4817 4818 // ----- Check that local file header is same as central file header4819 if ($this->privCheckFileHeaders($v_local_header,4820 $v_header_list[$i]) != 1) {4821 // TBC4822 }4823 unset($v_local_header);4824 4825 // ----- Write the file header4826 if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {4827 // ----- Close the zip file4828 $this->privCloseFd();4829 $v_temp_zip->privCloseFd();4830 @unlink($v_zip_temp_name);4831 4832 // ----- Return4833 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4834 return $v_result;4835 }4836 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset for this file is '".$v_header_list[$i]['offset']."'");4837 4838 // ----- Read/write the data block4839 if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {4840 // ----- Close the zip file4841 $this->privCloseFd();4842 $v_temp_zip->privCloseFd();4843 @unlink($v_zip_temp_name);4844 4845 // ----- Return4846 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4847 return $v_result;4848 }4849 }4850 4851 // ----- Store the offset of the central dir4852 $v_offset = @ftell($v_temp_zip->zip_fd);4853 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "New offset of central dir : $v_offset");4854 4855 // ----- Re-Create the Central Dir files header4856 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the new central directory");4857 for ($i=0; $i<sizeof($v_header_list); $i++) {4858 // ----- Create the file header4859 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset of file : ".$v_header_list[$i]['offset']);4860 if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {4861 $v_temp_zip->privCloseFd();4862 $this->privCloseFd();4863 @unlink($v_zip_temp_name);4864 4865 // ----- Return4866 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4867 return $v_result;4868 }4869 4870 // ----- Transform the header to a 'usable' info4871 $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);4872 }4873 4874 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the central directory footer");4875 4876 // ----- Zip file comment4877 $v_comment = '';4878 if (isset($p_options[PCLZIP_OPT_COMMENT])) {4879 $v_comment = $p_options[PCLZIP_OPT_COMMENT];4880 }4881 4882 // ----- Calculate the size of the central header4883 $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;4884 4885 // ----- Create the central dir footer4886 if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {4887 // ----- Reset the file list4888 unset($v_header_list);4889 $v_temp_zip->privCloseFd();4890 $this->privCloseFd();4891 @unlink($v_zip_temp_name);4892 4893 // ----- Return4894 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4895 return $v_result;4896 }4897 4898 // ----- Close4899 $v_temp_zip->privCloseFd();4900 $this->privCloseFd();4901 4902 // ----- Delete the zip file4903 // TBC : I should test the result ...4904 @unlink($this->zipname);4905 4906 // ----- Rename the temporary file4907 // TBC : I should test the result ...4908 //@rename($v_zip_temp_name, $this->zipname);4909 PclZipUtilRename($v_zip_temp_name, $this->zipname);4910 4911 // ----- Destroy the temporary archive4912 unset($v_temp_zip);4913 }4914 4915 // ----- Remove every files : reset the file4916 else if ($v_central_dir['entries'] != 0) {4917 $this->privCloseFd();4918 4919 if (($v_result = $this->privOpenFd('wb')) != 1) {4920 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4921 return $v_result;4922 }4923 4924 if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {4925 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4926 return $v_result;4927 }4928 4929 $this->privCloseFd();4930 }4931 4932 // ----- Return4933 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4934 return $v_result;5048 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByRule", ""); 5049 $v_result=1; 5050 $v_list_detail = array(); 5051 5052 // ----- Open the zip file 5053 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5054 if (($v_result=$this->privOpenFd('rb')) != 1) 5055 { 5056 // ----- Return 5057 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5058 return $v_result; 5059 } 5060 5061 // ----- Read the central directory informations 5062 $v_central_dir = array(); 5063 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 5064 { 5065 $this->privCloseFd(); 5066 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5067 return $v_result; 5068 } 5069 5070 // ----- Go to beginning of File 5071 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); 5072 @rewind($this->zip_fd); 5073 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); 5074 5075 // ----- Scan all the files 5076 // ----- Start at beginning of Central Dir 5077 $v_pos_entry = $v_central_dir['offset']; 5078 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); 5079 @rewind($this->zip_fd); 5080 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); 5081 if (@fseek($this->zip_fd, $v_pos_entry)) 5082 { 5083 // ----- Close the zip file 5084 $this->privCloseFd(); 5085 5086 // ----- Error log 5087 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 5088 5089 // ----- Return 5090 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5091 return PclZip::errorCode(); 5092 } 5093 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); 5094 5095 // ----- Read each entry 5096 $v_header_list = array(); 5097 $j_start = 0; 5098 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) 5099 { 5100 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry (index '$i')"); 5101 5102 // ----- Read the file header 5103 $v_header_list[$v_nb_extracted] = array(); 5104 if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) 5105 { 5106 // ----- Close the zip file 5107 $this->privCloseFd(); 5108 5109 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5110 return $v_result; 5111 } 5112 5113 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename (index '$i') : '".$v_header_list[$v_nb_extracted]['stored_filename']."'"); 5114 5115 // ----- Store the index 5116 $v_header_list[$v_nb_extracted]['index'] = $i; 5117 5118 // ----- Look for the specific extract rules 5119 $v_found = false; 5120 5121 // ----- Look for extract by name rule 5122 if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) 5123 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { 5124 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'"); 5125 5126 // ----- Look if the filename is in the list 5127 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { 5128 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'"); 5129 5130 // ----- Look for a directory 5131 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { 5132 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory"); 5133 5134 // ----- Look if the directory is in the filename path 5135 if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) 5136 && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { 5137 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path"); 5138 $v_found = true; 5139 } 5140 elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ 5141 && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { 5142 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The entry is the searched directory"); 5143 $v_found = true; 5144 } 5145 } 5146 // ----- Look for a filename 5147 elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { 5148 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one."); 5149 $v_found = true; 5150 } 5151 } 5152 } 5153 5154 // ----- Look for extract by ereg rule 5155 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) 5156 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { 5157 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'"); 5158 5159 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { 5160 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); 5161 $v_found = true; 5162 } 5163 } 5164 5165 // ----- Look for extract by preg rule 5166 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) 5167 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { 5168 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'"); 5169 5170 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { 5171 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); 5172 $v_found = true; 5173 } 5174 } 5175 5176 // ----- Look for extract by index rule 5177 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) 5178 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { 5179 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'"); 5180 5181 // ----- Look if the index is in the list 5182 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { 5183 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]"); 5184 5185 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { 5186 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range"); 5187 $v_found = true; 5188 } 5189 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { 5190 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop"); 5191 $j_start = $j+1; 5192 } 5193 5194 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { 5195 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop"); 5196 break; 5197 } 5198 } 5199 } 5200 else { 5201 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "No argument mean remove all file"); 5202 $v_found = true; 5203 } 5204 5205 // ----- Look for deletion 5206 if ($v_found) 5207 { 5208 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' need to be deleted"); 5209 unset($v_header_list[$v_nb_extracted]); 5210 } 5211 else 5212 { 5213 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' will not be deleted"); 5214 $v_nb_extracted++; 5215 } 5216 } 5217 5218 // ----- Look if something need to be deleted 5219 if ($v_nb_extracted > 0) { 5220 5221 // ----- Creates a temporay file 5222 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; 5223 5224 // ----- Creates a temporary zip archive 5225 $v_temp_zip = new PclZip($v_zip_temp_name); 5226 5227 // ----- Open the temporary zip file in write mode 5228 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary write mode"); 5229 if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) { 5230 $this->privCloseFd(); 5231 5232 // ----- Return 5233 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5234 return $v_result; 5235 } 5236 5237 // ----- Look which file need to be kept 5238 for ($i=0; $i<sizeof($v_header_list); $i++) { 5239 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Keep entry index '$i' : '".$v_header_list[$i]['filename']."'"); 5240 5241 // ----- Calculate the position of the header 5242 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset='". $v_header_list[$i]['offset']."'"); 5243 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); 5244 @rewind($this->zip_fd); 5245 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); 5246 if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { 5247 // ----- Close the zip file 5248 $this->privCloseFd(); 5249 $v_temp_zip->privCloseFd(); 5250 @unlink($v_zip_temp_name); 5251 5252 // ----- Error log 5253 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 5254 5255 // ----- Return 5256 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5257 return PclZip::errorCode(); 5258 } 5259 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); 5260 5261 // ----- Read the file header 5262 $v_local_header = array(); 5263 if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) { 5264 // ----- Close the zip file 5265 $this->privCloseFd(); 5266 $v_temp_zip->privCloseFd(); 5267 @unlink($v_zip_temp_name); 5268 5269 // ----- Return 5270 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5271 return $v_result; 5272 } 5273 5274 // ----- Check that local file header is same as central file header 5275 if ($this->privCheckFileHeaders($v_local_header, 5276 $v_header_list[$i]) != 1) { 5277 // TBC 5278 } 5279 unset($v_local_header); 5280 5281 // ----- Write the file header 5282 if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) { 5283 // ----- Close the zip file 5284 $this->privCloseFd(); 5285 $v_temp_zip->privCloseFd(); 5286 @unlink($v_zip_temp_name); 5287 5288 // ----- Return 5289 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5290 return $v_result; 5291 } 5292 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset for this file is '".$v_header_list[$i]['offset']."'"); 5293 5294 // ----- Read/write the data block 5295 if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) { 5296 // ----- Close the zip file 5297 $this->privCloseFd(); 5298 $v_temp_zip->privCloseFd(); 5299 @unlink($v_zip_temp_name); 5300 5301 // ----- Return 5302 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5303 return $v_result; 5304 } 5305 } 5306 5307 // ----- Store the offset of the central dir 5308 $v_offset = @ftell($v_temp_zip->zip_fd); 5309 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "New offset of central dir : $v_offset"); 5310 5311 // ----- Re-Create the Central Dir files header 5312 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the new central directory"); 5313 for ($i=0; $i<sizeof($v_header_list); $i++) { 5314 // ----- Create the file header 5315 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset of file : ".$v_header_list[$i]['offset']); 5316 if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) { 5317 $v_temp_zip->privCloseFd(); 5318 $this->privCloseFd(); 5319 @unlink($v_zip_temp_name); 5320 5321 // ----- Return 5322 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5323 return $v_result; 5324 } 5325 5326 // ----- Transform the header to a 'usable' info 5327 $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); 5328 } 5329 5330 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the central directory footer"); 5331 5332 // ----- Zip file comment 5333 $v_comment = ''; 5334 if (isset($p_options[PCLZIP_OPT_COMMENT])) { 5335 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; 5336 } 5337 5338 // ----- Calculate the size of the central header 5339 $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset; 5340 5341 // ----- Create the central dir footer 5342 if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) { 5343 // ----- Reset the file list 5344 unset($v_header_list); 5345 $v_temp_zip->privCloseFd(); 5346 $this->privCloseFd(); 5347 @unlink($v_zip_temp_name); 5348 5349 // ----- Return 5350 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5351 return $v_result; 5352 } 5353 5354 // ----- Close 5355 $v_temp_zip->privCloseFd(); 5356 $this->privCloseFd(); 5357 5358 // ----- Delete the zip file 5359 // TBC : I should test the result ... 5360 @unlink($this->zipname); 5361 5362 // ----- Rename the temporary file 5363 // TBC : I should test the result ... 5364 //@rename($v_zip_temp_name, $this->zipname); 5365 PclZipUtilRename($v_zip_temp_name, $this->zipname); 5366 5367 // ----- Destroy the temporary archive 5368 unset($v_temp_zip); 5369 } 5370 5371 // ----- Remove every files : reset the file 5372 else if ($v_central_dir['entries'] != 0) { 5373 $this->privCloseFd(); 5374 5375 if (($v_result = $this->privOpenFd('wb')) != 1) { 5376 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5377 return $v_result; 5378 } 5379 5380 if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) { 5381 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5382 return $v_result; 5383 } 5384 5385 $this->privCloseFd(); 5386 } 5387 5388 // ----- Return 5389 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5390 return $v_result; 4935 5391 } 4936 5392 // -------------------------------------------------------------------------------- … … 4944 5400 // $p_dir : Directory path to check. 4945 5401 // Return Values : 4946 // 1 : OK5402 // 1 : OK 4947 5403 // -1 : Unable to create directory 4948 5404 // -------------------------------------------------------------------------------- 4949 5405 function privDirCheck($p_dir, $p_is_dir=false) 4950 5406 { 4951 $v_result = 1;4952 4953 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDirCheck", "entry='$p_dir', is_dir='".($p_is_dir?"true":"false")."'");4954 4955 // ----- Remove the final '/'4956 if (($p_is_dir) && (substr($p_dir, -1)=='/'))4957 {4958 $p_dir = substr($p_dir, 0, strlen($p_dir)-1);4959 }4960 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for entry '$p_dir'");4961 4962 // ----- Check the directory availability4963 if ((is_dir($p_dir)) || ($p_dir == ""))4964 {4965 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, "'$p_dir' is a directory");4966 return 1;4967 }4968 4969 // ----- Extract parent directory4970 $p_parent_dir = dirname($p_dir);4971 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Parent directory is '$p_parent_dir'");4972 4973 // ----- Just a check4974 if ($p_parent_dir != $p_dir)4975 {4976 // ----- Look for parent directory4977 if ($p_parent_dir != "")4978 {4979 if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)4980 {4981 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4982 return $v_result;4983 }4984 }4985 }4986 4987 // ----- Create the directory4988 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Create directory '$p_dir'");4989 if (!@mkdir($p_dir, 0777))4990 {4991 // ----- Error log4992 PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");4993 4994 // ----- Return4995 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());4996 return PclZip::errorCode();4997 }4998 4999 // ----- Return5000 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result, "Directory '$p_dir' created");5001 return $v_result;5407 $v_result = 1; 5408 5409 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDirCheck", "entry='$p_dir', is_dir='".($p_is_dir?"true":"false")."'"); 5410 5411 // ----- Remove the final '/' 5412 if (($p_is_dir) && (substr($p_dir, -1)=='/')) 5413 { 5414 $p_dir = substr($p_dir, 0, strlen($p_dir)-1); 5415 } 5416 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for entry '$p_dir'"); 5417 5418 // ----- Check the directory availability 5419 if ((is_dir($p_dir)) || ($p_dir == "")) 5420 { 5421 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, "'$p_dir' is a directory"); 5422 return 1; 5423 } 5424 5425 // ----- Extract parent directory 5426 $p_parent_dir = dirname($p_dir); 5427 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Parent directory is '$p_parent_dir'"); 5428 5429 // ----- Just a check 5430 if ($p_parent_dir != $p_dir) 5431 { 5432 // ----- Look for parent directory 5433 if ($p_parent_dir != "") 5434 { 5435 if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) 5436 { 5437 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5438 return $v_result; 5439 } 5440 } 5441 } 5442 5443 // ----- Create the directory 5444 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Create directory '$p_dir'"); 5445 if (!@mkdir($p_dir, 0777)) 5446 { 5447 // ----- Error log 5448 PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); 5449 5450 // ----- Return 5451 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5452 return PclZip::errorCode(); 5453 } 5454 5455 // ----- Return 5456 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result, "Directory '$p_dir' created"); 5457 return $v_result; 5002 5458 } 5003 5459 // -------------------------------------------------------------------------------- … … 5012 5468 function privMerge(&$p_archive_to_add) 5013 5469 { 5014 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privMerge", "archive='".$p_archive_to_add->zipname."'");5015 $v_result=1;5016 5017 // ----- Look if the archive_to_add exists5018 if (!is_file($p_archive_to_add->zipname))5019 {5020 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to add does not exist. End of merge.");5021 5022 // ----- Nothing to merge, so merge is a success5023 $v_result = 1;5024 5025 // ----- Return5026 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5027 return $v_result;5028 }5029 5030 // ----- Look if the archive exists5031 if (!is_file($this->zipname))5032 {5033 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, duplicate the archive_to_add.");5034 5035 // ----- Do a duplicate5036 $v_result = $this->privDuplicate($p_archive_to_add->zipname);5037 5038 // ----- Return5039 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5040 return $v_result;5041 }5042 5043 // ----- Open the zip file5044 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");5045 if (($v_result=$this->privOpenFd('rb')) != 1)5046 {5047 // ----- Return5048 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5049 return $v_result;5050 }5051 5052 // ----- Read the central directory informations5053 $v_central_dir = array();5054 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)5055 {5056 $this->privCloseFd();5057 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5058 return $v_result;5059 }5060 5061 // ----- Go to beginning of File5062 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'");5063 @rewind($this->zip_fd);5064 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'");5065 5066 // ----- Open the archive_to_add file5067 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open archive_to_add in binary read mode");5068 if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)5069 {5070 $this->privCloseFd();5071 5072 // ----- Return5073 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5074 return $v_result;5075 }5076 5077 // ----- Read the central directory informations5078 $v_central_dir_to_add = array();5079 if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)5080 {5081 $this->privCloseFd();5082 $p_archive_to_add->privCloseFd();5083 5084 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5085 return $v_result;5086 }5087 5088 // ----- Go to beginning of File5089 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'");5090 @rewind($p_archive_to_add->zip_fd);5091 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'");5092 5093 // ----- Creates a temporay file5094 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';5095 5096 // ----- Open the temporary file in write mode5097 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");5098 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)5099 {5100 $this->privCloseFd();5101 $p_archive_to_add->privCloseFd();5102 5103 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');5104 5105 // ----- Return5106 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());5107 return PclZip::errorCode();5108 }5109 5110 // ----- Copy the files from the archive to the temporary file5111 // TBC : Here I should better append the file and go back to erase the central dir5112 $v_size = $v_central_dir['offset'];5113 while ($v_size != 0)5114 {5115 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);5116 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");5117 $v_buffer = fread($this->zip_fd, $v_read_size);5118 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);5119 $v_size -= $v_read_size;5120 }5121 5122 // ----- Copy the files from the archive_to_add into the temporary file5123 $v_size = $v_central_dir_to_add['offset'];5124 while ($v_size != 0)5125 {5126 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);5127 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");5128 $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);5129 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);5130 $v_size -= $v_read_size;5131 }5132 5133 // ----- Store the offset of the central dir5134 $v_offset = @ftell($v_zip_temp_fd);5135 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset");5136 5137 // ----- Copy the block of file headers from the old archive5138 $v_size = $v_central_dir['size'];5139 while ($v_size != 0)5140 {5141 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);5142 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");5143 $v_buffer = @fread($this->zip_fd, $v_read_size);5144 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);5145 $v_size -= $v_read_size;5146 }5147 5148 // ----- Copy the block of file headers from the archive_to_add5149 $v_size = $v_central_dir_to_add['size'];5150 while ($v_size != 0)5151 {5152 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);5153 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");5154 $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);5155 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);5156 $v_size -= $v_read_size;5157 }5158 5159 // ----- Merge the file comments5160 $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];5161 5162 // ----- Calculate the size of the (new) central header5163 $v_size = @ftell($v_zip_temp_fd)-$v_offset;5164 5165 // ----- Swap the file descriptor5166 // Here is a trick : I swap the temporary fd with the zip fd, in order to use5167 // the following methods on the temporary fil and not the real archive fd5168 $v_swap = $this->zip_fd;5169 $this->zip_fd = $v_zip_temp_fd;5170 $v_zip_temp_fd = $v_swap;5171 5172 // ----- Create the central dir footer5173 if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)5174 {5175 $this->privCloseFd();5176 $p_archive_to_add->privCloseFd();5177 @fclose($v_zip_temp_fd);5178 $this->zip_fd = null;5179 5180 // ----- Reset the file list5181 unset($v_header_list);5182 5183 // ----- Return5184 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5185 return $v_result;5186 }5187 5188 // ----- Swap back the file descriptor5189 $v_swap = $this->zip_fd;5190 $this->zip_fd = $v_zip_temp_fd;5191 $v_zip_temp_fd = $v_swap;5192 5193 // ----- Close5194 $this->privCloseFd();5195 $p_archive_to_add->privCloseFd();5196 5197 // ----- Close the temporary file5198 @fclose($v_zip_temp_fd);5199 5200 // ----- Delete the zip file5201 // TBC : I should test the result ...5202 @unlink($this->zipname);5203 5204 // ----- Rename the temporary file5205 // TBC : I should test the result ...5206 //@rename($v_zip_temp_name, $this->zipname);5207 PclZipUtilRename($v_zip_temp_name, $this->zipname);5208 5209 // ----- Return5210 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5211 return $v_result;5470 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privMerge", "archive='".$p_archive_to_add->zipname."'"); 5471 $v_result=1; 5472 5473 // ----- Look if the archive_to_add exists 5474 if (!is_file($p_archive_to_add->zipname)) 5475 { 5476 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to add does not exist. End of merge."); 5477 5478 // ----- Nothing to merge, so merge is a success 5479 $v_result = 1; 5480 5481 // ----- Return 5482 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5483 return $v_result; 5484 } 5485 5486 // ----- Look if the archive exists 5487 if (!is_file($this->zipname)) 5488 { 5489 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, duplicate the archive_to_add."); 5490 5491 // ----- Do a duplicate 5492 $v_result = $this->privDuplicate($p_archive_to_add->zipname); 5493 5494 // ----- Return 5495 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5496 return $v_result; 5497 } 5498 5499 // ----- Open the zip file 5500 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5501 if (($v_result=$this->privOpenFd('rb')) != 1) 5502 { 5503 // ----- Return 5504 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5505 return $v_result; 5506 } 5507 5508 // ----- Read the central directory informations 5509 $v_central_dir = array(); 5510 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 5511 { 5512 $this->privCloseFd(); 5513 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5514 return $v_result; 5515 } 5516 5517 // ----- Go to beginning of File 5518 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'"); 5519 @rewind($this->zip_fd); 5520 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'"); 5521 5522 // ----- Open the archive_to_add file 5523 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open archive_to_add in binary read mode"); 5524 if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) 5525 { 5526 $this->privCloseFd(); 5527 5528 // ----- Return 5529 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5530 return $v_result; 5531 } 5532 5533 // ----- Read the central directory informations 5534 $v_central_dir_to_add = array(); 5535 if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) 5536 { 5537 $this->privCloseFd(); 5538 $p_archive_to_add->privCloseFd(); 5539 5540 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5541 return $v_result; 5542 } 5543 5544 // ----- Go to beginning of File 5545 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'"); 5546 @rewind($p_archive_to_add->zip_fd); 5547 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'"); 5548 5549 // ----- Creates a temporay file 5550 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; 5551 5552 // ----- Open the temporary file in write mode 5553 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5554 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) 5555 { 5556 $this->privCloseFd(); 5557 $p_archive_to_add->privCloseFd(); 5558 5559 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); 5560 5561 // ----- Return 5562 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5563 return PclZip::errorCode(); 5564 } 5565 5566 // ----- Copy the files from the archive to the temporary file 5567 // TBC : Here I should better append the file and go back to erase the central dir 5568 $v_size = $v_central_dir['offset']; 5569 while ($v_size != 0) 5570 { 5571 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5572 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5573 $v_buffer = fread($this->zip_fd, $v_read_size); 5574 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 5575 $v_size -= $v_read_size; 5576 } 5577 5578 // ----- Copy the files from the archive_to_add into the temporary file 5579 $v_size = $v_central_dir_to_add['offset']; 5580 while ($v_size != 0) 5581 { 5582 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5583 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5584 $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); 5585 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 5586 $v_size -= $v_read_size; 5587 } 5588 5589 // ----- Store the offset of the central dir 5590 $v_offset = @ftell($v_zip_temp_fd); 5591 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset"); 5592 5593 // ----- Copy the block of file headers from the old archive 5594 $v_size = $v_central_dir['size']; 5595 while ($v_size != 0) 5596 { 5597 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5598 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5599 $v_buffer = @fread($this->zip_fd, $v_read_size); 5600 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 5601 $v_size -= $v_read_size; 5602 } 5603 5604 // ----- Copy the block of file headers from the archive_to_add 5605 $v_size = $v_central_dir_to_add['size']; 5606 while ($v_size != 0) 5607 { 5608 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5609 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5610 $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); 5611 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 5612 $v_size -= $v_read_size; 5613 } 5614 5615 // ----- Merge the file comments 5616 $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment']; 5617 5618 // ----- Calculate the size of the (new) central header 5619 $v_size = @ftell($v_zip_temp_fd)-$v_offset; 5620 5621 // ----- Swap the file descriptor 5622 // Here is a trick : I swap the temporary fd with the zip fd, in order to use 5623 // the following methods on the temporary fil and not the real archive fd 5624 $v_swap = $this->zip_fd; 5625 $this->zip_fd = $v_zip_temp_fd; 5626 $v_zip_temp_fd = $v_swap; 5627 5628 // ----- Create the central dir footer 5629 if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) 5630 { 5631 $this->privCloseFd(); 5632 $p_archive_to_add->privCloseFd(); 5633 @fclose($v_zip_temp_fd); 5634 $this->zip_fd = null; 5635 5636 // ----- Reset the file list 5637 unset($v_header_list); 5638 5639 // ----- Return 5640 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5641 return $v_result; 5642 } 5643 5644 // ----- Swap back the file descriptor 5645 $v_swap = $this->zip_fd; 5646 $this->zip_fd = $v_zip_temp_fd; 5647 $v_zip_temp_fd = $v_swap; 5648 5649 // ----- Close 5650 $this->privCloseFd(); 5651 $p_archive_to_add->privCloseFd(); 5652 5653 // ----- Close the temporary file 5654 @fclose($v_zip_temp_fd); 5655 5656 // ----- Delete the zip file 5657 // TBC : I should test the result ... 5658 @unlink($this->zipname); 5659 5660 // ----- Rename the temporary file 5661 // TBC : I should test the result ... 5662 //@rename($v_zip_temp_name, $this->zipname); 5663 PclZipUtilRename($v_zip_temp_name, $this->zipname); 5664 5665 // ----- Return 5666 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5667 return $v_result; 5212 5668 } 5213 5669 // -------------------------------------------------------------------------------- … … 5221 5677 function privDuplicate($p_archive_filename) 5222 5678 { 5223 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDuplicate", "archive_filename='$p_archive_filename'");5224 $v_result=1;5225 5226 // ----- Look if the $p_archive_filename exists5227 if (!is_file($p_archive_filename))5228 {5229 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to duplicate does not exist. End of duplicate.");5230 5231 // ----- Nothing to duplicate, so duplicate is a success.5232 $v_result = 1;5233 5234 // ----- Return5235 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5236 return $v_result;5237 }5238 5239 // ----- Open the zip file5240 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");5241 if (($v_result=$this->privOpenFd('wb')) != 1)5242 {5243 // ----- Return5244 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5245 return $v_result;5246 }5247 5248 // ----- Open the temporary file in write mode5249 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");5250 if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)5251 {5252 $this->privCloseFd();5253 5254 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');5255 5256 // ----- Return5257 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());5258 return PclZip::errorCode();5259 }5260 5261 // ----- Copy the files from the archive to the temporary file5262 // TBC : Here I should better append the file and go back to erase the central dir5263 $v_size = filesize($p_archive_filename);5264 while ($v_size != 0)5265 {5266 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);5267 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read $v_read_size bytes");5268 $v_buffer = fread($v_zip_temp_fd, $v_read_size);5269 @fwrite($this->zip_fd, $v_buffer, $v_read_size);5270 $v_size -= $v_read_size;5271 }5272 5273 // ----- Close5274 $this->privCloseFd();5275 5276 // ----- Close the temporary file5277 @fclose($v_zip_temp_fd);5278 5279 // ----- Return5280 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5281 return $v_result;5679 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDuplicate", "archive_filename='$p_archive_filename'"); 5680 $v_result=1; 5681 5682 // ----- Look if the $p_archive_filename exists 5683 if (!is_file($p_archive_filename)) 5684 { 5685 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to duplicate does not exist. End of duplicate."); 5686 5687 // ----- Nothing to duplicate, so duplicate is a success. 5688 $v_result = 1; 5689 5690 // ----- Return 5691 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5692 return $v_result; 5693 } 5694 5695 // ----- Open the zip file 5696 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5697 if (($v_result=$this->privOpenFd('wb')) != 1) 5698 { 5699 // ----- Return 5700 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5701 return $v_result; 5702 } 5703 5704 // ----- Open the temporary file in write mode 5705 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5706 if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) 5707 { 5708 $this->privCloseFd(); 5709 5710 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); 5711 5712 // ----- Return 5713 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5714 return PclZip::errorCode(); 5715 } 5716 5717 // ----- Copy the files from the archive to the temporary file 5718 // TBC : Here I should better append the file and go back to erase the central dir 5719 $v_size = filesize($p_archive_filename); 5720 while ($v_size != 0) 5721 { 5722 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5723 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read $v_read_size bytes"); 5724 $v_buffer = fread($v_zip_temp_fd, $v_read_size); 5725 @fwrite($this->zip_fd, $v_buffer, $v_read_size); 5726 $v_size -= $v_read_size; 5727 } 5728 5729 // ----- Close 5730 $this->privCloseFd(); 5731 5732 // ----- Close the temporary file 5733 @fclose($v_zip_temp_fd); 5734 5735 // ----- Return 5736 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5737 return $v_result; 5282 5738 } 5283 5739 // -------------------------------------------------------------------------------- … … 5290 5746 function privErrorLog($p_error_code=0, $p_error_string='') 5291 5747 { 5292 if (PCLZIP_ERROR_EXTERNAL == 1) {5293 PclError($p_error_code, $p_error_string);5294 }5295 else {5296 $this->error_code = $p_error_code;5297 $this->error_string = $p_error_string;5298 }5748 if (PCLZIP_ERROR_EXTERNAL == 1) { 5749 PclError($p_error_code, $p_error_string); 5750 } 5751 else { 5752 $this->error_code = $p_error_code; 5753 $this->error_string = $p_error_string; 5754 } 5299 5755 } 5300 5756 // -------------------------------------------------------------------------------- … … 5307 5763 function privErrorReset() 5308 5764 { 5309 if (PCLZIP_ERROR_EXTERNAL == 1) {5310 PclErrorReset();5311 }5312 else {5313 $this->error_code = 0;5314 $this->error_string = '';5315 }5765 if (PCLZIP_ERROR_EXTERNAL == 1) { 5766 PclErrorReset(); 5767 } 5768 else { 5769 $this->error_code = 0; 5770 $this->error_string = ''; 5771 } 5316 5772 } 5317 5773 // -------------------------------------------------------------------------------- … … 5325 5781 function privDecrypt($p_encryption_header, &$p_buffer, $p_size, $p_crc) 5326 5782 { 5327 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDecrypt', "size=".$p_size."");5328 $v_result=1;5329 5330 // ----- To Be Modified ;-)5331 $v_pwd = "test";5332 5333 $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header,5334 $p_crc, $v_pwd);5335 5336 // ----- Return5337 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5338 return $v_result;5783 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDecrypt', "size=".$p_size.""); 5784 $v_result=1; 5785 5786 // ----- To Be Modified ;-) 5787 $v_pwd = "test"; 5788 5789 $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header, 5790 $p_crc, $v_pwd); 5791 5792 // ----- Return 5793 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5794 return $v_result; 5339 5795 } 5340 5796 // -------------------------------------------------------------------------------- … … 5348 5804 function privDisableMagicQuotes() 5349 5805 { 5350 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDisableMagicQuotes', "");5351 $v_result=1;5352 5353 // ----- Look if function exists5354 if ( (!function_exists("get_magic_quotes_runtime"))5355 || (!function_exists("set_magic_quotes_runtime"))) {5356 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported");5357 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5358 return $v_result;5359 } 5360 5361 // ----- Look if already done5362 if ($this->magic_quotes_status != -1) {5363 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote already disabled");5364 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5365 return $v_result;5806 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDisableMagicQuotes', ""); 5807 $v_result=1; 5808 5809 // ----- Look if function exists 5810 if ( (!function_exists("get_magic_quotes_runtime")) 5811 || (!function_exists("set_magic_quotes_runtime"))) { 5812 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported"); 5813 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5814 return $v_result; 5815 } 5816 5817 // ----- Look if already done 5818 if ($this->magic_quotes_status != -1) { 5819 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote already disabled"); 5820 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5821 return $v_result; 5366 5822 } 5367 5823 5368 5824 // ----- Get and memorize the magic_quote value 5369 5825 $this->magic_quotes_status = @get_magic_quotes_runtime(); 5370 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Current magic_quotes_runtime status is '".($this->magic_quotes_status==0?'disable':'enable')."'");5826 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Current magic_quotes_runtime status is '".($this->magic_quotes_status==0?'disable':'enable')."'"); 5371 5827 5372 5828 // ----- Disable magic_quotes 5373 5829 if ($this->magic_quotes_status == 1) { 5374 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Disable magic_quotes");5830 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Disable magic_quotes"); 5375 5831 @set_magic_quotes_runtime(0); 5376 5832 } 5377 5833 5378 // ----- Return5379 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5380 return $v_result;5834 // ----- Return 5835 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5836 return $v_result; 5381 5837 } 5382 5838 // -------------------------------------------------------------------------------- … … 5390 5846 function privSwapBackMagicQuotes() 5391 5847 { 5392 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privSwapBackMagicQuotes', "");5393 $v_result=1;5394 5395 // ----- Look if function exists5396 if ( (!function_exists("get_magic_quotes_runtime"))5397 || (!function_exists("set_magic_quotes_runtime"))) {5398 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported");5399 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5400 return $v_result;5401 } 5402 5403 // ----- Look if something to do5404 if ($this->magic_quotes_status != -1) {5405 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote not modified");5406 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5407 return $v_result;5848 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privSwapBackMagicQuotes', ""); 5849 $v_result=1; 5850 5851 // ----- Look if function exists 5852 if ( (!function_exists("get_magic_quotes_runtime")) 5853 || (!function_exists("set_magic_quotes_runtime"))) { 5854 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported"); 5855 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5856 return $v_result; 5857 } 5858 5859 // ----- Look if something to do 5860 if ($this->magic_quotes_status != -1) { 5861 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote not modified"); 5862 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5863 return $v_result; 5408 5864 } 5409 5865 5410 5866 // ----- Swap back magic_quotes 5411 5867 if ($this->magic_quotes_status == 1) { 5412 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Enable back magic_quotes");5868 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Enable back magic_quotes"); 5413 5869 @set_magic_quotes_runtime($this->magic_quotes_status); 5414 5870 } 5415 5871 5416 // ----- Return5417 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5418 return $v_result;5872 // ----- Return 5873 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5874 return $v_result; 5419 5875 } 5420 5876 // -------------------------------------------------------------------------------- … … 5432 5888 function PclZipUtilPathReduction($p_dir) 5433 5889 { 5434 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathReduction", "dir='$p_dir'");5435 $v_result = "";5436 5437 // ----- Look for not empty path5438 if ($p_dir != "") {5439 // ----- Explode path by directory names5440 $v_list = explode("/", $p_dir);5441 5442 // ----- Study directories from last to first5443 $v_skip = 0;5444 for ($i=sizeof($v_list)-1; $i>=0; $i--) {5445 // ----- Look for current path5446 if ($v_list[$i] == ".") {5447 // ----- Ignore this directory5448 // Should be the first $i=0, but no check is done5449 }5450 else if ($v_list[$i] == "..") {5890 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathReduction", "dir='$p_dir'"); 5891 $v_result = ""; 5892 5893 // ----- Look for not empty path 5894 if ($p_dir != "") { 5895 // ----- Explode path by directory names 5896 $v_list = explode("/", $p_dir); 5897 5898 // ----- Study directories from last to first 5899 $v_skip = 0; 5900 for ($i=sizeof($v_list)-1; $i>=0; $i--) { 5901 // ----- Look for current path 5902 if ($v_list[$i] == ".") { 5903 // ----- Ignore this directory 5904 // Should be the first $i=0, but no check is done 5905 } 5906 else if ($v_list[$i] == "..") { 5451 5907 $v_skip++; 5452 }5453 else if ($v_list[$i] == "") {5908 } 5909 else if ($v_list[$i] == "") { 5454 5910 // ----- First '/' i.e. root slash 5455 5911 if ($i == 0) { 5456 $v_result = "/".$v_result;5457 if ($v_skip > 0) {5458 // ----- It is an invalid path, so the path is not modified5459 // TBC5460 $v_result = $p_dir;5461 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid path is unchanged");5462 $v_skip = 0;5463 }5912 $v_result = "/".$v_result; 5913 if ($v_skip > 0) { 5914 // ----- It is an invalid path, so the path is not modified 5915 // TBC 5916 $v_result = $p_dir; 5917 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid path is unchanged"); 5918 $v_skip = 0; 5919 } 5464 5920 } 5465 5921 // ----- Last '/' i.e. indicates a directory 5466 5922 else if ($i == (sizeof($v_list)-1)) { 5467 $v_result = $v_list[$i];5923 $v_result = $v_list[$i]; 5468 5924 } 5469 5925 // ----- Double '/' inside the path 5470 5926 else { 5471 // ----- Ignore only the double '//' in path,5472 // but not the first and last '/'5473 } 5474 }5475 else {5927 // ----- Ignore only the double '//' in path, 5928 // but not the first and last '/' 5929 } 5930 } 5931 else { 5476 5932 // ----- Look for item to skip 5477 5933 if ($v_skip > 0) { 5478 $v_skip--;5934 $v_skip--; 5479 5935 } 5480 5936 else { 5481 $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");5482 } 5483 }5484 }5485 5486 // ----- Look for skip5487 if ($v_skip > 0) {5488 while ($v_skip > 0) {5489 $v_result = '../'.$v_result;5490 $v_skip--;5491 }5492 }5493 }5494 5495 // ----- Return5496 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5497 return $v_result;5937 $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); 5938 } 5939 } 5940 } 5941 5942 // ----- Look for skip 5943 if ($v_skip > 0) { 5944 while ($v_skip > 0) { 5945 $v_result = '../'.$v_result; 5946 $v_skip--; 5947 } 5948 } 5949 } 5950 5951 // ----- Return 5952 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5953 return $v_result; 5498 5954 } 5499 5955 // -------------------------------------------------------------------------------- … … 5516 5972 function PclZipUtilPathInclusion($p_dir, $p_path) 5517 5973 { 5518 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathInclusion", "dir='$p_dir', path='$p_path'");5519 $v_result = 1;5520 5521 // ----- Look for path beginning by ./5522 if ( ($p_dir == '.')5523 || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {5524 $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);5525 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_dir '".$p_dir."'");5526 }5527 if ( ($p_path == '.')5528 || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {5529 $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);5530 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_path '".$p_path."'");5531 }5532 5533 // ----- Explode dir and path by directory separator5534 $v_list_dir = explode("/", $p_dir);5535 $v_list_dir_size = sizeof($v_list_dir);5536 $v_list_path = explode("/", $p_path);5537 $v_list_path_size = sizeof($v_list_path);5538 5539 // ----- Study directories paths5540 $i = 0;5541 $j = 0;5542 while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {5543 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Working on dir($i)='".$v_list_dir[$i]."' and path($j)='".$v_list_path[$j]."'");5544 5545 // ----- Look for empty dir (path reduction)5546 if ($v_list_dir[$i] == '') {5547 $i++;5548 continue;5549 }5550 if ($v_list_path[$j] == '') {5551 $j++;5552 continue;5553 }5554 5555 // ----- Compare the items5556 if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) {5557 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Items ($i,$j) are different");5558 $v_result = 0;5559 }5560 5561 // ----- Next items5562 $i++;5563 $j++;5564 }5565 5566 // ----- Look if everything seems to be the same5567 if ($v_result) {5568 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Look for tie break");5569 // ----- Skip all the empty items5570 while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;5571 while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;5572 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Looking on dir($i)='".($i < $v_list_dir_size?$v_list_dir[$i]:'')."' and path($j)='".($j < $v_list_path_size?$v_list_path[$j]:'')."'");5573 5574 if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {5575 // ----- There are exactly the same5576 $v_result = 2;5577 }5578 else if ($i < $v_list_dir_size) {5579 // ----- The path is shorter than the dir5580 $v_result = 0;5581 }5582 }5583 5584 // ----- Return5585 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5586 return $v_result;5974 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathInclusion", "dir='$p_dir', path='$p_path'"); 5975 $v_result = 1; 5976 5977 // ----- Look for path beginning by ./ 5978 if ( ($p_dir == '.') 5979 || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { 5980 $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); 5981 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_dir '".$p_dir."'"); 5982 } 5983 if ( ($p_path == '.') 5984 || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { 5985 $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); 5986 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_path '".$p_path."'"); 5987 } 5988 5989 // ----- Explode dir and path by directory separator 5990 $v_list_dir = explode("/", $p_dir); 5991 $v_list_dir_size = sizeof($v_list_dir); 5992 $v_list_path = explode("/", $p_path); 5993 $v_list_path_size = sizeof($v_list_path); 5994 5995 // ----- Study directories paths 5996 $i = 0; 5997 $j = 0; 5998 while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) { 5999 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Working on dir($i)='".$v_list_dir[$i]."' and path($j)='".$v_list_path[$j]."'"); 6000 6001 // ----- Look for empty dir (path reduction) 6002 if ($v_list_dir[$i] == '') { 6003 $i++; 6004 continue; 6005 } 6006 if ($v_list_path[$j] == '') { 6007 $j++; 6008 continue; 6009 } 6010 6011 // ----- Compare the items 6012 if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { 6013 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Items ($i,$j) are different"); 6014 $v_result = 0; 6015 } 6016 6017 // ----- Next items 6018 $i++; 6019 $j++; 6020 } 6021 6022 // ----- Look if everything seems to be the same 6023 if ($v_result) { 6024 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Look for tie break"); 6025 // ----- Skip all the empty items 6026 while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; 6027 while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; 6028 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Looking on dir($i)='".($i < $v_list_dir_size?$v_list_dir[$i]:'')."' and path($j)='".($j < $v_list_path_size?$v_list_path[$j]:'')."'"); 6029 6030 if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { 6031 // ----- There are exactly the same 6032 $v_result = 2; 6033 } 6034 else if ($i < $v_list_dir_size) { 6035 // ----- The path is shorter than the dir 6036 $v_result = 0; 6037 } 6038 } 6039 6040 // ----- Return 6041 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 6042 return $v_result; 5587 6043 } 5588 6044 // -------------------------------------------------------------------------------- … … 5593 6049 // Parameters : 5594 6050 // $p_mode : read/write compression mode 5595 // 0 : src & dest normal5596 // 1 : src gzip, dest normal5597 // 2 : src normal, dest gzip5598 // 3 : src & dest gzip6051 // 0 : src & dest normal 6052 // 1 : src gzip, dest normal 6053 // 2 : src normal, dest gzip 6054 // 3 : src & dest gzip 5599 6055 // Return Values : 5600 6056 // -------------------------------------------------------------------------------- 5601 6057 function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) 5602 6058 { 5603 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilCopyBlock", "size=$p_size, mode=$p_mode");5604 $v_result = 1;5605 5606 if ($p_mode==0)5607 {5608 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset before read :".(@ftell($p_src)));5609 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset before write :".(@ftell($p_dest)));5610 while ($p_size != 0)5611 {5612 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);5613 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");5614 $v_buffer = @fread($p_src, $v_read_size);5615 @fwrite($p_dest, $v_buffer, $v_read_size);5616 $p_size -= $v_read_size;5617 }5618 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset after read :".(@ftell($p_src)));5619 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset after write :".(@ftell($p_dest)));5620 }5621 else if ($p_mode==1)5622 {5623 while ($p_size != 0)5624 {5625 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);5626 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");5627 $v_buffer = @gzread($p_src, $v_read_size);5628 @fwrite($p_dest, $v_buffer, $v_read_size);5629 $p_size -= $v_read_size;5630 }5631 }5632 else if ($p_mode==2)5633 {5634 while ($p_size != 0)5635 {5636 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);5637 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");5638 $v_buffer = @fread($p_src, $v_read_size);5639 @gzwrite($p_dest, $v_buffer, $v_read_size);5640 $p_size -= $v_read_size;5641 }5642 }5643 else if ($p_mode==3)5644 {5645 while ($p_size != 0)5646 {5647 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);5648 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");5649 $v_buffer = @gzread($p_src, $v_read_size);5650 @gzwrite($p_dest, $v_buffer, $v_read_size);5651 $p_size -= $v_read_size;5652 }5653 }5654 5655 // ----- Return5656 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5657 return $v_result;6059 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilCopyBlock", "size=$p_size, mode=$p_mode"); 6060 $v_result = 1; 6061 6062 if ($p_mode==0) 6063 { 6064 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset before read :".(@ftell($p_src))); 6065 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset before write :".(@ftell($p_dest))); 6066 while ($p_size != 0) 6067 { 6068 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 6069 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 6070 $v_buffer = @fread($p_src, $v_read_size); 6071 @fwrite($p_dest, $v_buffer, $v_read_size); 6072 $p_size -= $v_read_size; 6073 } 6074 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset after read :".(@ftell($p_src))); 6075 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset after write :".(@ftell($p_dest))); 6076 } 6077 else if ($p_mode==1) 6078 { 6079 while ($p_size != 0) 6080 { 6081 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 6082 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 6083 $v_buffer = @gzread($p_src, $v_read_size); 6084 @fwrite($p_dest, $v_buffer, $v_read_size); 6085 $p_size -= $v_read_size; 6086 } 6087 } 6088 else if ($p_mode==2) 6089 { 6090 while ($p_size != 0) 6091 { 6092 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 6093 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 6094 $v_buffer = @fread($p_src, $v_read_size); 6095 @gzwrite($p_dest, $v_buffer, $v_read_size); 6096 $p_size -= $v_read_size; 6097 } 6098 } 6099 else if ($p_mode==3) 6100 { 6101 while ($p_size != 0) 6102 { 6103 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 6104 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 6105 $v_buffer = @gzread($p_src, $v_read_size); 6106 @gzwrite($p_dest, $v_buffer, $v_read_size); 6107 $p_size -= $v_read_size; 6108 } 6109 } 6110 6111 // ----- Return 6112 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 6113 return $v_result; 5658 6114 } 5659 6115 // -------------------------------------------------------------------------------- … … 5673 6129 function PclZipUtilRename($p_src, $p_dest) 5674 6130 { 5675 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilRename", "source=$p_src, destination=$p_dest");5676 $v_result = 1;5677 5678 // ----- Try to rename the files5679 if (!@rename($p_src, $p_dest)) {5680 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to rename file, try copy+unlink");5681 5682 // ----- Try to copy & unlink the src5683 if (!@copy($p_src, $p_dest)) {5684 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to copy file");5685 $v_result = 0;5686 }5687 else if (!@unlink($p_src)) {5688 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to unlink old filename");5689 $v_result = 0;5690 }5691 }5692 5693 // ----- Return5694 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5695 return $v_result;6131 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilRename", "source=$p_src, destination=$p_dest"); 6132 $v_result = 1; 6133 6134 // ----- Try to rename the files 6135 if (!@rename($p_src, $p_dest)) { 6136 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to rename file, try copy+unlink"); 6137 6138 // ----- Try to copy & unlink the src 6139 if (!@copy($p_src, $p_dest)) { 6140 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to copy file"); 6141 $v_result = 0; 6142 } 6143 else if (!@unlink($p_src)) { 6144 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to unlink old filename"); 6145 $v_result = 0; 6146 } 6147 } 6148 6149 // ----- Return 6150 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 6151 return $v_result; 5696 6152 } 5697 6153 // -------------------------------------------------------------------------------- … … 5708 6164 function PclZipUtilOptionText($p_option) 5709 6165 { 5710 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilOptionText", "option='".$p_option."'");5711 5712 $v_list = get_defined_constants();5713 for (reset($v_list); $v_key = key($v_list); next($v_list)) {6166 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilOptionText", "option='".$p_option."'"); 6167 6168 $v_list = get_defined_constants(); 6169 for (reset($v_list); $v_key = key($v_list); next($v_list)) { 5714 6170 $v_prefix = substr($v_key, 0, 10); 5715 6171 if (( ($v_prefix == 'PCLZIP_OPT') 5716 || ($v_prefix == 'PCLZIP_CB_')5717 || ($v_prefix == 'PCLZIP_ATT'))5718 && ($v_list[$v_key] == $p_option)) {5719 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_key);5720 return $v_key;5721 }5722 }5723 5724 $v_result = 'Unknown';5725 5726 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5727 return $v_result;6172 || ($v_prefix == 'PCLZIP_CB_') 6173 || ($v_prefix == 'PCLZIP_ATT')) 6174 && ($v_list[$v_key] == $p_option)) { 6175 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_key); 6176 return $v_key; 6177 } 6178 } 6179 6180 $v_result = 'Unknown'; 6181 6182 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 6183 return $v_result; 5728 6184 } 5729 6185 // -------------------------------------------------------------------------------- … … 5742 6198 function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true) 5743 6199 { 5744 if (stristr(php_uname(), 'windows')) {5745 // ----- Look for potential disk letter5746 if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {5747 $p_path = substr($p_path, $v_position+1);5748 }5749 // ----- Change potential windows directory separator5750 if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {5751 $p_path = strtr($p_path, '\\', '/');5752 }5753 }5754 return $p_path;6200 if (stristr(php_uname(), 'windows')) { 6201 // ----- Look for potential disk letter 6202 if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { 6203 $p_path = substr($p_path, $v_position+1); 6204 } 6205 // ----- Change potential windows directory separator 6206 if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { 6207 $p_path = strtr($p_path, '\\', '/'); 6208 } 6209 } 6210 return $p_path; 5755 6211 } 5756 6212 // --------------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.