Changeset 11038 for trunk/wp-admin/includes/class-pclzip.php
- Timestamp:
- 04/21/2009 10:42:25 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
r11025 r11038 28 28 // ----- Constants 29 29 if (!defined('PCLZIP_READ_BLOCK_SIZE')) { 30 define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );30 define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); 31 31 } 32 32 … … 42 42 // Recommanded values for smart separation of filenames. 43 43 if (!defined('PCLZIP_SEPARATOR')) { 44 define( 'PCLZIP_SEPARATOR', ',' );44 define( 'PCLZIP_SEPARATOR', ',' ); 45 45 } 46 46 … … 48 48 // 0 : PclZip Class integrated error handling 49 49 // 1 : PclError external library error handling. By enabling this 50 // you must ensure that you have included PclError library.50 // you must ensure that you have included PclError library. 51 51 // [2,...] : reserved for futur use 52 52 if (!defined('PCLZIP_ERROR_EXTERNAL')) { 53 define( 'PCLZIP_ERROR_EXTERNAL', 0 );53 define( 'PCLZIP_ERROR_EXTERNAL', 0 ); 54 54 } 55 55 56 56 // ----- Optional static temporary directory 57 // By default temporary files are generated in the script current58 // path.59 // If defined :60 // - MUST BE terminated by a '/'.61 // - MUST be a valid, already created directory62 // 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 : 63 63 // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' ); 64 64 // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' ); 65 65 if (!defined('PCLZIP_TEMPORARY_DIR')) { 66 define( 'PCLZIP_TEMPORARY_DIR', '' );66 define( 'PCLZIP_TEMPORARY_DIR', '' ); 67 67 } 68 68 … … 175 175 class PclZip 176 176 { 177 // ----- Filename of the zip file178 var $zipname = '';179 180 // ----- File descriptor of the zip file181 var $zip_fd = 0;182 183 // ----- Internal error handling184 var $error_code = 1;185 var $error_string = '';186 187 // ----- Current status of the magic_quotes_runtime188 // This value store the php configuration for magic_quotes189 // The class can then disable the magic_quotes and reset it after190 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; 191 191 192 192 // -------------------------------------------------------------------------------- … … 200 200 function PclZip($p_zipname) 201 201 { 202 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname");203 204 // ----- Tests the zlib205 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 attributes212 $this->zipname = $p_zipname;213 $this->zip_fd = 0;214 $this->magic_quotes_status = -1;215 216 // ----- Return217 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1);218 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; 219 219 } 220 220 // -------------------------------------------------------------------------------- … … 236 236 // Parameters : 237 237 // $p_filelist : An array containing file or directory names, or 238 // a string containing one filename or one directory name, or239 // a string containing a list of filenames and/or directory240 // 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. 241 241 // $p_add_dir : A path to add before the real path of the archived file, 242 // in order to have it memorized in the archive.242 // in order to have it memorized in the archive. 243 243 // $p_remove_dir : A path to remove from the real path of the file to archive, 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_dir246 // 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. 247 247 // Options : 248 248 // PCLZIP_OPT_ADD_PATH : … … 259 259 function create($p_filelist) 260 260 { 261 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ...");262 $v_result=1;263 264 // ----- Reset the error handler265 $this->privErrorReset();266 267 // ----- Set default values268 $v_options = array();269 $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;270 271 // ----- Look for variable options arguments272 $v_size = func_num_args();273 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");274 275 // ----- Look for arguments276 if ($v_size > 1) {277 // ----- Get the arguments278 $v_arg_list = func_get_args();279 280 // ----- Remove from the options list the first argument281 array_shift($v_arg_list);282 $v_size--;283 284 // ----- Look for first arg285 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 options289 $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 args309 // Here we need to support the first historic synopsis of the310 // method.311 else {312 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");313 314 // ----- Get the first argument315 $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];316 317 // ----- Look for the optional second argument318 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 values331 if (!isset($v_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) {332 $this->privOptionDefaultThreshold($v_options);333 }334 335 // ----- Init336 $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 array342 if (is_array($p_filelist)) {343 344 // ----- Look if the first element is also an array345 //This will mean that this is a file description entry346 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 names351 else {352 $v_string_list = $p_filelist;353 }354 }355 356 // ----- Look if the $p_filelist is a string357 else if (is_string($p_filelist)) {358 // ----- Create a list from the string359 $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);360 }361 362 // ----- Invalid variable type for $p_filelist363 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 list370 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 attributes382 $v_supported_attributes383 = 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'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' 389 389 ); 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 fct409 $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 // ----- Return416 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);417 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; 418 418 } 419 419 // -------------------------------------------------------------------------------- … … 431 431 // Parameters : 432 432 // $p_filelist : An array containing file or directory names, or 433 // a string containing one filename or one directory name, or434 // a string containing a list of filenames and/or directory435 // 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. 436 436 // $p_add_dir : A path to add before the real path of the archived file, 437 // in order to have it memorized in the archive.437 // in order to have it memorized in the archive. 438 438 // $p_remove_dir : A path to remove from the real path of the file to archive, 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_dir441 // 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. 442 442 // Options : 443 443 // PCLZIP_OPT_ADD_PATH : … … 456 456 function add($p_filelist) 457 457 { 458 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ...");459 $v_result=1;460 461 // ----- Reset the error handler462 $this->privErrorReset();463 464 // ----- Set default values465 $v_options = array();466 $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;467 468 // ----- Look for variable options arguments469 $v_size = func_num_args();470 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");471 472 // ----- Look for arguments473 if ($v_size > 1) {474 // ----- Get the arguments475 $v_arg_list = func_get_args();476 477 // ----- Remove form the options list the first argument478 array_shift($v_arg_list);479 $v_size--;480 481 // ----- Look for first arg482 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 options486 $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'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' 500 500 )); 501 if ($v_result != 1) {502 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);503 return 0;504 }505 }506 507 // ----- Look for 2 args508 // Here we need to support the first historic synopsis of the509 // method.510 else {511 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");512 513 // ----- Get the first argument514 $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];515 516 // ----- Look for the optional second argument517 if ($v_size == 2) {518 $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];519 }520 else if ($v_size > 2) {521 // ----- Error log522 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");523 524 // ----- Return525 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());526 return 0;527 }528 }529 }530 531 // ----- Look for default option values532 if (!isset($v_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) {533 $this->privOptionDefaultThreshold($v_options);534 }535 536 // ----- Init537 $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 array543 if (is_array($p_filelist)) {544 545 // ----- Look if the first element is also an array546 //This will mean that this is a file description entry547 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 names552 else {553 $v_string_list = $p_filelist;554 }555 }556 557 // ----- Look if the $p_filelist is a string558 else if (is_string($p_filelist)) {559 // ----- Create a list from the string560 $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);561 }562 563 // ----- Invalid variable type for $p_filelist564 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 list571 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 attributes578 $v_supported_attributes579 = 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'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' 585 585 ); 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 fct605 $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 // ----- Return612 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);613 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; 614 614 } 615 615 // -------------------------------------------------------------------------------- … … 621 621 // properties. 622 622 // The properties of each entries in the list are (used also in other functions) : 623 // filename : Name of the file. For a create or add action it is the filename624 // given by the user. For an extract function it is the filename625 // 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 archive629 // (without the headers overhead)630 // mtime : Last known modification date of the file (UNIX timestamp)631 // comment : Comment associated with the file632 // folder : true | false633 // index : index of the file in the archive634 // 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 a639 // directory with the same name already exists640 // write_protected : the file can not be extracted because a file641 // with the same name already exists and is642 // write protected643 // newer_exist : the file was not extracted because a newer file exists644 // path_creation_fail : the file is not extracted because the folder645 // does not exist and can not be created646 // write_error : the file was not extracted because there was a647 // error while writing the file648 // read_error : the file was not extracted because there was a error649 // while reading the file650 // invalid_header : the file was not extracted because of an archive651 // 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) 652 652 // Note that each time a method can continue operating when there 653 653 // is an action error on a file, the error is only logged in the file status. … … 658 658 function listContent() 659 659 { 660 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', "");661 $v_result=1;662 663 // ----- Reset the error handler664 $this->privErrorReset();665 666 // ----- Check archive667 if (!$this->privCheckFormat()) {668 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);669 return(0);670 }671 672 // ----- Call the extracting fct673 $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 // ----- Return682 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);683 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; 684 684 } 685 685 // -------------------------------------------------------------------------------- … … 704 704 // $p_path : Path where the files and directories are to be extracted 705 705 // $p_remove_path : First part ('root' part) of the memorized path 706 // (if any similar) to remove while extracting.706 // (if any similar) to remove while extracting. 707 707 // Options : 708 708 // PCLZIP_OPT_PATH : … … 719 719 function extract() 720 720 { 721 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", "");722 $v_result=1;723 724 // ----- Reset the error handler725 $this->privErrorReset();726 727 // ----- Check archive728 if (!$this->privCheckFormat()) {729 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);730 return(0);731 }732 733 // ----- Set default values734 $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 arguments741 $v_size = func_num_args();742 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");743 744 // ----- Default values for option745 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;746 747 // ----- Look for arguments748 if ($v_size > 0) {749 // ----- Get the arguments750 $v_arg_list = func_get_args();751 752 // ----- Look for first arg753 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 options757 $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 arguments781 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 char792 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 args800 // Here we need to support the first historic synopsis of the801 // method.802 else {803 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");804 805 // ----- Get the first argument806 $v_path = $v_arg_list[0];807 808 // ----- Look for the optional second argument809 if ($v_size == 2) {810 $v_remove_path = $v_arg_list[1];811 }812 else if ($v_size > 2) {813 // ----- Error log814 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");815 816 // ----- Return817 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());818 return 0;819 }820 }821 }822 823 // ----- Trace824 //--(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 fct827 $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 // ----- Return837 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);838 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; 839 839 } 840 840 // -------------------------------------------------------------------------------- … … 854 854 // Parameters : 855 855 // $p_index : A single index (integer) or a string of indexes of files to 856 // extract. The form of the string is "0,4-6,8-12" with only numbers857 // and '-' for range or ',' to separate ranges. No spaces or ';'858 // 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. 859 859 // $p_path : Path where the files and directories are to be extracted 860 860 // $p_remove_path : First part ('root' part) of the memorized path 861 // (if any similar) to remove while extracting.861 // (if any similar) to remove while extracting. 862 862 // Options : 863 863 // PCLZIP_OPT_PATH : … … 866 866 // PCLZIP_OPT_REMOVE_ALL_PATH : 867 867 // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and 868 // not as files.869 // The resulting content is in a new field 'content' in the file870 // structure.871 // 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). 872 872 // PCLZIP_CB_PRE_EXTRACT : 873 873 // PCLZIP_CB_POST_EXTRACT : … … 880 880 function extractByIndex($p_index) 881 881 { 882 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ...");883 $v_result=1;884 885 // ----- Reset the error handler886 $this->privErrorReset();887 888 // ----- Check archive889 if (!$this->privCheckFormat()) {890 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);891 return(0);892 }893 894 // ----- Set default values895 $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 arguments902 $v_size = func_num_args();903 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");904 905 // ----- Default values for option906 $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;907 908 // ----- Look for arguments909 if ($v_size > 1) {910 // ----- Get the arguments911 $v_arg_list = func_get_args();912 913 // ----- Remove form the options list the first argument914 array_shift($v_arg_list);915 $v_size--;916 917 // ----- Look for first arg918 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 options922 $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'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' 934 934 )); 935 if ($v_result != 1) {936 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);937 return 0;938 }939 940 // ----- Set the arguments941 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 char952 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 args967 // Here we need to support the first historic synopsis of the968 // method.969 else {970 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");971 972 // ----- Get the first argument973 $v_path = $v_arg_list[0];974 975 // ----- Look for the optional second argument976 if ($v_size == 2) {977 $v_remove_path = $v_arg_list[1];978 }979 else if ($v_size > 2) {980 // ----- Error log981 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");982 983 // ----- Return984 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());985 return 0;986 }987 }988 }989 990 // ----- Trace991 //--(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 // ----- Trick994 // Here I want to reuse extractByRule(), so I need to parse the $p_index995 // 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 fct1007 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 // ----- Return1013 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);1014 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; 1015 1015 } 1016 1016 // -------------------------------------------------------------------------------- … … 1036 1036 function delete() 1037 1037 { 1038 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", "");1039 $v_result=1;1040 1041 // ----- Reset the error handler1042 $this->privErrorReset();1043 1044 // ----- Check archive1045 if (!$this->privCheckFormat()) {1046 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);1047 return(0);1048 }1049 1050 // ----- Set default values1051 $v_options = array();1052 1053 // ----- Look for variable options arguments1054 $v_size = func_num_args();1055 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");1056 1057 // ----- Look for arguments1058 if ($v_size > 0) {1059 // ----- Get the arguments1060 $v_arg_list = func_get_args();1061 1062 // ----- Parse the options1063 $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 trick1075 $this->privDisableMagicQuotes();1076 1077 // ----- Call the delete fct1078 $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 trick1087 $this->privSwapBackMagicQuotes();1088 1089 // ----- Return1090 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list);1091 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; 1092 1092 } 1093 1093 // -------------------------------------------------------------------------------- … … 1101 1101 function deleteByIndex($p_index) 1102 1102 { 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 // ----- Return1108 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);1109 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; 1110 1110 } 1111 1111 // -------------------------------------------------------------------------------- … … 1116 1116 // This method gives the properties of the archive. 1117 1117 // The properties are : 1118 // nb : Number of files in the archive1119 // comment : Comment associated with the archive file1120 // status : not_exist, ok1118 // nb : Number of files in the archive 1119 // comment : Comment associated with the archive file 1120 // status : not_exist, ok 1121 1121 // Parameters : 1122 1122 // None … … 1127 1127 function properties() 1128 1128 { 1129 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", "");1130 1131 // ----- Reset the error handler1132 $this->privErrorReset();1133 1134 // ----- Magic quotes trick1135 $this->privDisableMagicQuotes();1136 1137 // ----- Check archive1138 if (!$this->privCheckFormat()) {1139 $this->privSwapBackMagicQuotes();1140 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);1141 return(0);1142 }1143 1144 // ----- Default properties1145 $v_prop = array();1146 $v_prop['comment'] = '';1147 $v_prop['nb'] = 0;1148 $v_prop['status'] = 'not_exist';1149 1150 // ----- Look if file exists1151 if (@is_file($this->zipname))1152 {1153 // ----- Open the zip file1154 //--(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 log1160 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');1161 1162 // ----- Return1163 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0);1164 return 0;1165 }1166 1167 // ----- Read the central directory informations1168 $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 file1177 $this->privCloseFd();1178 1179 // ----- Set the user attributes1180 $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 trick1186 $this->privSwapBackMagicQuotes();1187 1188 // ----- Return1189 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop);1190 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; 1191 1191 } 1192 1192 // -------------------------------------------------------------------------------- … … 1199 1199 // Parameters : 1200 1200 // $p_archive : The filename of a valid archive, or 1201 // a valid PclZip object.1201 // a valid PclZip object. 1202 1202 // Return Values : 1203 1203 // 1 on success. … … 1206 1206 function duplicate($p_archive) 1207 1207 { 1208 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", "");1209 $v_result = 1;1210 1211 // ----- Reset the error handler1212 $this->privErrorReset();1213 1214 // ----- Look if the $p_archive is a PclZip object1215 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 archive1220 $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 file1229 // TBC : Should also check the archive format1230 if (!is_file($p_archive)) {1231 // ----- Error log1232 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 archive1237 $v_result = $this->privDuplicate($p_archive);1238 }1239 }1240 1241 // ----- Invalid variable1242 else1243 {1244 // ----- Error log1245 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");1246 $v_result = PCLZIP_ERR_INVALID_PARAMETER;1247 }1248 1249 // ----- Return1250 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);1251 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; 1252 1252 } 1253 1253 // -------------------------------------------------------------------------------- … … 1262 1262 // Parameters : 1263 1263 // $p_archive_to_add : It can be directly the filename of a valid zip archive, 1264 // or a PclZip object archive.1264 // or a PclZip object archive. 1265 1265 // Return Values : 1266 1266 // 1 on success, … … 1269 1269 function merge($p_archive_to_add) 1270 1270 { 1271 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", "");1272 $v_result = 1;1273 1274 // ----- Reset the error handler1275 $this->privErrorReset();1276 1277 // ----- Check archive1278 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 object1284 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 archive1289 $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 archive1298 $v_object_archive = new PclZip($p_archive_to_add);1299 1300 // ----- Merge the archive1301 $v_result = $this->privMerge($v_object_archive);1302 }1303 1304 // ----- Invalid variable1305 else1306 {1307 // ----- Error log1308 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");1309 $v_result = PCLZIP_ERR_INVALID_PARAMETER;1310 }1311 1312 // ----- Return1313 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);1314 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; 1315 1315 } 1316 1316 // -------------------------------------------------------------------------------- … … 1325 1325 function errorCode() 1326 1326 { 1327 if (PCLZIP_ERROR_EXTERNAL == 1) {1328 return(PclErrorCode());1329 }1330 else {1331 return($this->error_code);1332 }1327 if (PCLZIP_ERROR_EXTERNAL == 1) { 1328 return(PclErrorCode()); 1329 } 1330 else { 1331 return($this->error_code); 1332 } 1333 1333 } 1334 1334 // -------------------------------------------------------------------------------- … … 1341 1341 function errorName($p_with_code=false) 1342 1342 { 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 }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 } 1379 1379 } 1380 1380 // -------------------------------------------------------------------------------- … … 1387 1387 function errorInfo($p_full=false) 1388 1388 { 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 }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 } 1400 1400 } 1401 1401 // -------------------------------------------------------------------------------- … … 1404 1404 // -------------------------------------------------------------------------------- 1405 1405 // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS ***** 1406 // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY ***** 1406 // ***** ***** 1407 // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY ***** 1407 1408 // -------------------------------------------------------------------------------- 1408 1409 … … 1416 1417 // Parameters : 1417 1418 // $p_level : Level of check. Default 0. 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)1419 // 0 : Check the first bytes (magic codes) (default value)) 1420 // 1 : 0 + Check the central directory (futur) 1421 // 2 : 1 + Check each file header (futur) 1421 1422 // Return Values : 1422 1423 // true on success, … … 1425 1426 function privCheckFormat($p_level=0) 1426 1427 { 1427 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", "");1428 $v_result = true;1428 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", ""); 1429 $v_result = true; 1429 1430 1430 1431 // ----- Reset the file system cache 1431 clearstatcache();1432 1433 // ----- Reset the error handler1434 $this->privErrorReset();1435 1436 // ----- Look if the file exits1437 if (!is_file($this->zipname)) {1438 // ----- Error log1439 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 readeable1445 if (!is_readable($this->zipname)) {1446 // ----- Error log1447 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 code1453 // TBC1454 1455 // ----- Check the central header1456 // TBC1457 1458 // ----- Check each file header1459 // TBC1460 1461 // ----- Return1462 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);1463 return $v_result;1432 clearstatcache(); 1433 1434 // ----- Reset the error handler 1435 $this->privErrorReset(); 1436 1437 // ----- Look if the file exits 1438 if (!is_file($this->zipname)) { 1439 // ----- Error log 1440 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); 1441 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo()); 1442 return(false); 1443 } 1444 1445 // ----- Check that the file is readeable 1446 if (!is_readable($this->zipname)) { 1447 // ----- Error log 1448 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); 1449 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo()); 1450 return(false); 1451 } 1452 1453 // ----- Check the magic code 1454 // TBC 1455 1456 // ----- Check the central header 1457 // TBC 1458 1459 // ----- Check each file header 1460 // TBC 1461 1462 // ----- Return 1463 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1464 return $v_result; 1464 1465 } 1465 1466 // -------------------------------------------------------------------------------- … … 1482 1483 function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) 1483 1484 { 1484 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", "");1485 $v_result=1;1486 1487 // ----- Read the options1488 $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 supported1493 if (!isset($v_requested_options[$p_options_list[$i]])) {1494 // ----- Error log1495 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");1496 1497 // ----- Return1498 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1499 return PclZip::errorCode();1500 }1501 1502 // ----- Look for next option1503 switch ($p_options_list[$i]) {1504 // ----- Look for options that request a path value1505 case PCLZIP_OPT_PATH :1506 case PCLZIP_OPT_REMOVE_PATH :1507 case PCLZIP_OPT_ADD_PATH :1508 // ----- Check the number of parameters1509 if (($i+1) >= $p_size) {1510 // ----- Error log1511 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");1512 1513 // ----- Return1514 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1515 return PclZip::errorCode();1516 }1517 1518 // ----- Get the value1519 $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 parameters1526 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 options1533 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 value1540 $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 options1555 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 options1567 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 options1573 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 parameters1585 if (($i+1) >= $p_size) {1586 // ----- Error log1587 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");1588 1589 // ----- Return1590 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1591 return PclZip::errorCode();1592 }1593 1594 // ----- Get the value1595 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 value1607 case PCLZIP_OPT_BY_NAME :1608 // ----- Check the number of parameters1609 if (($i+1) >= $p_size) {1610 // ----- Error log1611 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");1612 1613 // ----- Return1614 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1615 return PclZip::errorCode();1616 }1617 1618 // ----- Get the value1619 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 log1627 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");1628 1629 // ----- Return1630 //--(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 expression1638 case PCLZIP_OPT_BY_EREG :1639 case PCLZIP_OPT_BY_PREG :1640 //case PCLZIP_OPT_CRYPT :1641 // ----- Check the number of parameters1642 if (($i+1) >= $p_size) {1643 // ----- Error log1644 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");1645 1646 // ----- Return1647 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1648 return PclZip::errorCode();1649 }1650 1651 // ----- Get the value1652 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 log1657 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");1658 1659 // ----- Return1660 //--(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 string1668 case PCLZIP_OPT_COMMENT :1669 case PCLZIP_OPT_ADD_COMMENT :1670 case PCLZIP_OPT_PREPEND_COMMENT :1671 // ----- Check the number of parameters1672 if (($i+1) >= $p_size) {1673 // ----- Error log1674 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,1675 "Missing parameter value for option '"1485 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", ""); 1486 $v_result=1; 1487 1488 // ----- Read the options 1489 $i=0; 1490 while ($i<$p_size) { 1491 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'"); 1492 1493 // ----- Check if the option is supported 1494 if (!isset($v_requested_options[$p_options_list[$i]])) { 1495 // ----- Error log 1496 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); 1497 1498 // ----- Return 1499 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1500 return PclZip::errorCode(); 1501 } 1502 1503 // ----- Look for next option 1504 switch ($p_options_list[$i]) { 1505 // ----- Look for options that request a path value 1506 case PCLZIP_OPT_PATH : 1507 case PCLZIP_OPT_REMOVE_PATH : 1508 case PCLZIP_OPT_ADD_PATH : 1509 // ----- Check the number of parameters 1510 if (($i+1) >= $p_size) { 1511 // ----- Error log 1512 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1513 1514 // ----- Return 1515 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1516 return PclZip::errorCode(); 1517 } 1518 1519 // ----- Get the value 1520 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); 1521 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1522 $i++; 1523 break; 1524 1525 case PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD : 1526 // ----- Check the number of parameters 1527 if (($i+1) >= $p_size) { 1528 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1529 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1530 return PclZip::errorCode(); 1531 } 1532 1533 // ----- Check for incompatible options 1534 if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_OFF])) { 1535 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_OFF'"); 1536 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1537 return PclZip::errorCode(); 1538 } 1539 1540 // ----- Check the value 1541 $v_value = $p_options_list[$i+1]; 1542 if ((!is_integer($v_value)) || ($v_value<0)) { 1543 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1544 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1545 return PclZip::errorCode(); 1546 } 1547 1548 // ----- Get the value (and convert it in bytes) 1549 $v_result_list[$p_options_list[$i]] = $v_value*1048576; 1550 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1551 $i++; 1552 break; 1553 1554 case PCLZIP_OPT_ADD_TEMP_FILE_ON : 1555 // ----- Check for incompatible options 1556 if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_OFF])) { 1557 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_OFF'"); 1558 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1559 return PclZip::errorCode(); 1560 } 1561 1562 $v_result_list[$p_options_list[$i]] = true; 1563 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1564 break; 1565 1566 case PCLZIP_OPT_ADD_TEMP_FILE_OFF : 1567 // ----- Check for incompatible options 1568 if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_ON])) { 1569 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_ON'"); 1570 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1571 return PclZip::errorCode(); 1572 } 1573 // ----- Check for incompatible options 1574 if (isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) { 1575 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD'"); 1576 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1577 return PclZip::errorCode(); 1578 } 1579 1580 $v_result_list[$p_options_list[$i]] = true; 1581 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1582 break; 1583 1584 case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : 1585 // ----- Check the number of parameters 1586 if (($i+1) >= $p_size) { 1587 // ----- Error log 1588 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1589 1590 // ----- Return 1591 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1592 return PclZip::errorCode(); 1593 } 1594 1595 // ----- Get the value 1596 if ( is_string($p_options_list[$i+1]) 1597 && ($p_options_list[$i+1] != '')) { 1598 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); 1599 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1600 $i++; 1601 } 1602 else { 1603 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored."); 1604 } 1605 break; 1606 1607 // ----- Look for options that request an array of string for value 1608 case PCLZIP_OPT_BY_NAME : 1609 // ----- Check the number of parameters 1610 if (($i+1) >= $p_size) { 1611 // ----- Error log 1612 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1613 1614 // ----- Return 1615 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1616 return PclZip::errorCode(); 1617 } 1618 1619 // ----- Get the value 1620 if (is_string($p_options_list[$i+1])) { 1621 $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; 1622 } 1623 else if (is_array($p_options_list[$i+1])) { 1624 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1625 } 1626 else { 1627 // ----- Error log 1628 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1629 1630 // ----- Return 1631 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1632 return PclZip::errorCode(); 1633 } 1634 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1635 $i++; 1636 break; 1637 1638 // ----- Look for options that request an EREG or PREG expression 1639 case PCLZIP_OPT_BY_EREG : 1640 case PCLZIP_OPT_BY_PREG : 1641 //case PCLZIP_OPT_CRYPT : 1642 // ----- Check the number of parameters 1643 if (($i+1) >= $p_size) { 1644 // ----- Error log 1645 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1646 1647 // ----- Return 1648 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1649 return PclZip::errorCode(); 1650 } 1651 1652 // ----- Get the value 1653 if (is_string($p_options_list[$i+1])) { 1654 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1655 } 1656 else { 1657 // ----- Error log 1658 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1659 1660 // ----- Return 1661 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1662 return PclZip::errorCode(); 1663 } 1664 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1665 $i++; 1666 break; 1667 1668 // ----- Look for options that takes a string 1669 case PCLZIP_OPT_COMMENT : 1670 case PCLZIP_OPT_ADD_COMMENT : 1671 case PCLZIP_OPT_PREPEND_COMMENT : 1672 // ----- Check the number of parameters 1673 if (($i+1) >= $p_size) { 1674 // ----- Error log 1675 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, 1676 "Missing parameter value for option '" 1676 1677 .PclZipUtilOptionText($p_options_list[$i]) 1677 1678 ."'"); 1678 1679 1679 // ----- Return1680 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1681 return PclZip::errorCode();1682 }1683 1684 // ----- Get the value1685 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 log1690 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,1691 "Wrong parameter value for option '"1680 // ----- Return 1681 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1682 return PclZip::errorCode(); 1683 } 1684 1685 // ----- Get the value 1686 if (is_string($p_options_list[$i+1])) { 1687 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1688 } 1689 else { 1690 // ----- Error log 1691 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, 1692 "Wrong parameter value for option '" 1692 1693 .PclZipUtilOptionText($p_options_list[$i]) 1693 1694 ."'"); 1694 1695 1695 // ----- Return1696 //--(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 index1704 case PCLZIP_OPT_BY_INDEX :1705 // ----- Check the number of parameters1706 if (($i+1) >= $p_size) {1707 // ----- Error log1708 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");1709 1710 // ----- Return1711 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1712 return PclZip::errorCode();1713 }1714 1715 // ----- Get the value1716 $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 spaces1721 $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');1722 1723 // ----- Parse items1724 $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 log1736 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array 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 // ----- Reduce the index list1744 // each index item in the list must be a couple with a start and1745 // an end value : [0,3], [5-5], [8-10], ...1746 // ----- Check the format of each item1747 $v_sort_flag=false;1748 $v_sort_value=0;1749 for ($j=0; $j<sizeof($v_work_list); $j++) {1750 // ----- Explode the item1751 $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 a1755 // real integer ...1756 1757 // ----- Look for single value1758 if ($v_size_item_list == 1) {1759 // ----- Set the option value1760 $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 value1765 $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 log1770 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");1771 1772 // ----- Return1773 //--(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 sort1780 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 log1786 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");1787 1788 // ----- Return1789 //--(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 items1796 if ($v_sort_flag) {1797 // TBC : To Be Completed1798 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ...");1799 }1800 1801 // ----- Next option1802 $i++;1803 break;1804 1805 // ----- Look for options that request no value1806 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 value1817 case PCLZIP_OPT_SET_CHMOD :1818 // ----- Check the number of parameters1819 if (($i+1) >= $p_size) {1820 // ----- Error log1821 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");1822 1823 // ----- Return1824 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1825 return PclZip::errorCode();1826 }1827 1828 // ----- Get the value1829 $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-back1835 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 use1840 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 parameters1846 if (($i+1) >= $p_size) {1847 // ----- Error log1848 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");1849 1850 // ----- Return1851 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1852 return PclZip::errorCode();1853 }1854 1855 // ----- Get the value1856 $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 function1860 if (!function_exists($v_function_name)) {1861 // ----- Error log1862 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 // ----- Return1865 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1866 return PclZip::errorCode();1867 }1868 1869 // ----- Set the attribute1870 $v_result_list[$p_options_list[$i]] = $v_function_name;1871 $i++;1872 break;1873 1874 default :1875 // ----- Error log1876 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,1877 "Unknown parameter '"1696 // ----- Return 1697 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1698 return PclZip::errorCode(); 1699 } 1700 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1701 $i++; 1702 break; 1703 1704 // ----- Look for options that request an array of index 1705 case PCLZIP_OPT_BY_INDEX : 1706 // ----- Check the number of parameters 1707 if (($i+1) >= $p_size) { 1708 // ----- Error log 1709 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1710 1711 // ----- Return 1712 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1713 return PclZip::errorCode(); 1714 } 1715 1716 // ----- Get the value 1717 $v_work_list = array(); 1718 if (is_string($p_options_list[$i+1])) { 1719 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'"); 1720 1721 // ----- Remove spaces 1722 $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); 1723 1724 // ----- Parse items 1725 $v_work_list = explode(",", $p_options_list[$i+1]); 1726 } 1727 else if (is_integer($p_options_list[$i+1])) { 1728 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an integer '".$p_options_list[$i+1]."'"); 1729 $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; 1730 } 1731 else if (is_array($p_options_list[$i+1])) { 1732 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array"); 1733 $v_work_list = $p_options_list[$i+1]; 1734 } 1735 else { 1736 // ----- Error log 1737 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1738 1739 // ----- Return 1740 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1741 return PclZip::errorCode(); 1742 } 1743 1744 // ----- Reduce the index list 1745 // each index item in the list must be a couple with a start and 1746 // an end value : [0,3], [5-5], [8-10], ... 1747 // ----- Check the format of each item 1748 $v_sort_flag=false; 1749 $v_sort_value=0; 1750 for ($j=0; $j<sizeof($v_work_list); $j++) { 1751 // ----- Explode the item 1752 $v_item_list = explode("-", $v_work_list[$j]); 1753 $v_size_item_list = sizeof($v_item_list); 1754 1755 // ----- TBC : Here we might check that each item is a 1756 // real integer ... 1757 1758 // ----- Look for single value 1759 if ($v_size_item_list == 1) { 1760 // ----- Set the option value 1761 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; 1762 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; 1763 } 1764 elseif ($v_size_item_list == 2) { 1765 // ----- Set the option value 1766 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; 1767 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; 1768 } 1769 else { 1770 // ----- Error log 1771 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1772 1773 // ----- Return 1774 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1775 return PclZip::errorCode(); 1776 } 1777 1778 //--(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']."]"); 1779 1780 // ----- Look for list sort 1781 if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { 1782 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The list should be sorted ..."); 1783 $v_sort_flag=true; 1784 1785 // ----- TBC : An automatic sort should be writen ... 1786 // ----- Error log 1787 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1788 1789 // ----- Return 1790 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1791 return PclZip::errorCode(); 1792 } 1793 $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; 1794 } 1795 1796 // ----- Sort the items 1797 if ($v_sort_flag) { 1798 // TBC : To Be Completed 1799 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ..."); 1800 } 1801 1802 // ----- Next option 1803 $i++; 1804 break; 1805 1806 // ----- Look for options that request no value 1807 case PCLZIP_OPT_REMOVE_ALL_PATH : 1808 case PCLZIP_OPT_EXTRACT_AS_STRING : 1809 case PCLZIP_OPT_NO_COMPRESSION : 1810 case PCLZIP_OPT_EXTRACT_IN_OUTPUT : 1811 case PCLZIP_OPT_REPLACE_NEWER : 1812 case PCLZIP_OPT_STOP_ON_ERROR : 1813 $v_result_list[$p_options_list[$i]] = true; 1814 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1815 break; 1816 1817 // ----- Look for options that request an octal value 1818 case PCLZIP_OPT_SET_CHMOD : 1819 // ----- Check the number of parameters 1820 if (($i+1) >= $p_size) { 1821 // ----- Error log 1822 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1823 1824 // ----- Return 1825 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1826 return PclZip::errorCode(); 1827 } 1828 1829 // ----- Get the value 1830 $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; 1831 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1832 $i++; 1833 break; 1834 1835 // ----- Look for options that request a call-back 1836 case PCLZIP_CB_PRE_EXTRACT : 1837 case PCLZIP_CB_POST_EXTRACT : 1838 case PCLZIP_CB_PRE_ADD : 1839 case PCLZIP_CB_POST_ADD : 1840 /* for futur use 1841 case PCLZIP_CB_PRE_DELETE : 1842 case PCLZIP_CB_POST_DELETE : 1843 case PCLZIP_CB_PRE_LIST : 1844 case PCLZIP_CB_POST_LIST : 1845 */ 1846 // ----- Check the number of parameters 1847 if (($i+1) >= $p_size) { 1848 // ----- Error log 1849 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1850 1851 // ----- Return 1852 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1853 return PclZip::errorCode(); 1854 } 1855 1856 // ----- Get the value 1857 $v_function_name = $p_options_list[$i+1]; 1858 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "call-back ".PclZipUtilOptionText($p_options_list[$i])." = '".$v_function_name."'"); 1859 1860 // ----- Check that the value is a valid existing function 1861 if (!function_exists($v_function_name)) { 1862 // ----- Error log 1863 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 1864 1865 // ----- Return 1866 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1867 return PclZip::errorCode(); 1868 } 1869 1870 // ----- Set the attribute 1871 $v_result_list[$p_options_list[$i]] = $v_function_name; 1872 $i++; 1873 break; 1874 1875 default : 1876 // ----- Error log 1877 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 1878 "Unknown parameter '" 1878 1879 .$p_options_list[$i]."'"); 1879 1880 1880 // ----- Return1881 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1882 return PclZip::errorCode();1883 }1884 1885 // ----- Next options1886 $i++;1887 }1888 1889 // ----- Look for mandatory options1890 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 option1893 if ($v_requested_options[$key] == 'mandatory') {1894 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");1895 // ----- Look if present1896 if (!isset($v_result_list[$key])) {1897 // ----- Error log1898 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");1899 1900 // ----- Return1901 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1902 return PclZip::errorCode();1903 }1904 }1905 }1906 }1907 1908 // ----- Look for default values1909 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 // ----- Return1915 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);1916 return $v_result;1881 // ----- Return 1882 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1883 return PclZip::errorCode(); 1884 } 1885 1886 // ----- Next options 1887 $i++; 1888 } 1889 1890 // ----- Look for mandatory options 1891 if ($v_requested_options !== false) { 1892 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { 1893 // ----- Look for mandatory option 1894 if ($v_requested_options[$key] == 'mandatory') { 1895 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); 1896 // ----- Look if present 1897 if (!isset($v_result_list[$key])) { 1898 // ----- Error log 1899 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); 1900 1901 // ----- Return 1902 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1903 return PclZip::errorCode(); 1904 } 1905 } 1906 } 1907 } 1908 1909 // ----- Look for default values 1910 if (!isset($v_result_list[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD])) { 1911 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Calculate auto threshold"); 1912 1913 } 1914 1915 // ----- Return 1916 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1917 return $v_result; 1917 1918 } 1918 1919 // -------------------------------------------------------------------------------- … … 1926 1927 function privOptionDefaultThreshold(&$p_options) 1927 1928 { 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 value1933 $v_memory_limit = ini_get('memory_limit');1934 $v_memory_limit = trim($v_memory_limit);1935 $last = strtolower(substr($v_memory_limit, -1));1929 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOptionDefaultThreshold", ""); 1930 $v_result=1; 1931 1932 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Create an auto-threshold for use of temporay files"); 1933 // ----- Get 'memory_limit' configuration value 1934 $v_memory_limit = ini_get('memory_limit'); 1935 $v_memory_limit = trim($v_memory_limit); 1936 $last = strtolower(substr($v_memory_limit, -1)); 1936 1937 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 1M1951 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 // ----- Return1957 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);1958 return $v_result;1938 if($last == 'g') 1939 //$v_memory_limit = $v_memory_limit*1024*1024*1024; 1940 $v_memory_limit = $v_memory_limit*1073741824; 1941 if($last == 'm') 1942 //$v_memory_limit = $v_memory_limit*1024*1024; 1943 $v_memory_limit = $v_memory_limit*1048576; 1944 if($last == 'k') 1945 $v_memory_limit = $v_memory_limit*1024; 1946 1947 $p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD] = floor($v_memory_limit/2); 1948 1949 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Threshold value is : ".$p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD]." bytes"); 1950 1951 // ----- Sanity check : No threshold if value lower than 1M 1952 if ($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD] < 1048576) { 1953 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3,"Unset the threshold (value ".$p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD].") because under 1Mo sanity check)"); 1954 unset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD]); 1955 } 1956 1957 // ----- Return 1958 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1959 return $v_result; 1959 1960 } 1960 1961 // -------------------------------------------------------------------------------- … … 1970 1971 function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) 1971 1972 { 1972 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", "");1973 $v_result=1;1974 1975 // ----- For each file in the list check the attributes1976 foreach ($p_file_list as $v_key => $v_value) {1977 1978 // ----- Check if the option is supported1979 if (!isset($v_requested_options[$v_key])) {1980 // ----- Error log1981 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");1982 1983 // ----- Return1984 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());1985 return PclZip::errorCode();1986 }1987 1988 // ----- Look for attribute1989 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 string2043 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 log2072 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,2073 "Unknown parameter '".$v_key."'");2074 2075 // ----- Return2076 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());2077 return PclZip::errorCode();2078 }2079 2080 // ----- Look for mandatory options2081 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 option2084 if ($v_requested_options[$key] == 'mandatory') {2085 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");2086 // ----- Look if present2087 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 foreach2097 }2098 2099 // ----- Return2100 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2101 return $v_result;1973 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", ""); 1974 $v_result=1; 1975 1976 // ----- For each file in the list check the attributes 1977 foreach ($p_file_list as $v_key => $v_value) { 1978 1979 // ----- Check if the option is supported 1980 if (!isset($v_requested_options[$v_key])) { 1981 // ----- Error log 1982 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); 1983 1984 // ----- Return 1985 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1986 return PclZip::errorCode(); 1987 } 1988 1989 // ----- Look for attribute 1990 switch ($v_key) { 1991 case PCLZIP_ATT_FILE_NAME : 1992 if (!is_string($v_value)) { 1993 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 1994 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1995 return PclZip::errorCode(); 1996 } 1997 1998 $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); 1999 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 2000 2001 if ($p_filedescr['filename'] == '') { 2002 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); 2003 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2004 return PclZip::errorCode(); 2005 } 2006 2007 break; 2008 2009 case PCLZIP_ATT_FILE_NEW_SHORT_NAME : 2010 if (!is_string($v_value)) { 2011 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 2012 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2013 return PclZip::errorCode(); 2014 } 2015 2016 $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); 2017 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 2018 2019 if ($p_filedescr['new_short_name'] == '') { 2020 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); 2021 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2022 return PclZip::errorCode(); 2023 } 2024 break; 2025 2026 case PCLZIP_ATT_FILE_NEW_FULL_NAME : 2027 if (!is_string($v_value)) { 2028 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 2029 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2030 return PclZip::errorCode(); 2031 } 2032 2033 $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); 2034 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 2035 2036 if ($p_filedescr['new_full_name'] == '') { 2037 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); 2038 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2039 return PclZip::errorCode(); 2040 } 2041 break; 2042 2043 // ----- Look for options that takes a string 2044 case PCLZIP_ATT_FILE_COMMENT : 2045 if (!is_string($v_value)) { 2046 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); 2047 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2048 return PclZip::errorCode(); 2049 } 2050 2051 $p_filedescr['comment'] = $v_value; 2052 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 2053 break; 2054 2055 case PCLZIP_ATT_FILE_MTIME : 2056 if (!is_integer($v_value)) { 2057 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); 2058 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2059 return PclZip::errorCode(); 2060 } 2061 2062 $p_filedescr['mtime'] = $v_value; 2063 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 2064 break; 2065 2066 case PCLZIP_ATT_FILE_CONTENT : 2067 $p_filedescr['content'] = $v_value; 2068 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 2069 break; 2070 2071 default : 2072 // ----- Error log 2073 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, 2074 "Unknown parameter '".$v_key."'"); 2075 2076 // ----- Return 2077 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2078 return PclZip::errorCode(); 2079 } 2080 2081 // ----- Look for mandatory options 2082 if ($v_requested_options !== false) { 2083 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { 2084 // ----- Look for mandatory option 2085 if ($v_requested_options[$key] == 'mandatory') { 2086 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); 2087 // ----- Look if present 2088 if (!isset($p_file_list[$key])) { 2089 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); 2090 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2091 return PclZip::errorCode(); 2092 } 2093 } 2094 } 2095 } 2096 2097 // end foreach 2098 } 2099 2100 // ----- Return 2101 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2102 return $v_result; 2102 2103 } 2103 2104 // -------------------------------------------------------------------------------- … … 2119 2120 function privFileDescrExpand(&$p_filedescr_list, &$p_options) 2120 2121 { 2121 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", "");2122 $v_result=1;2123 2124 // ----- Create a result list2125 $v_result_list = array();2126 2127 // ----- Look each entry2128 for ($i=0; $i<sizeof($p_filedescr_list); $i++) {2129 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for file ".$i.".");2130 2131 // ----- Get filedescr2132 $v_descr = $p_filedescr_list[$i];2133 2134 // ----- Reduce the filename2135 //--(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 folder2141 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 // skip2153 continue;2154 }2155 else {2156 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type");2157 // skip2158 continue;2159 }2160 }2161 2162 // ----- Look for string added as file2163 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 file2169 else {2170 // ----- Error log2171 //--(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 // ----- Return2175 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());2176 return PclZip::errorCode();2177 }2178 2179 // ----- Calculate the stored filename2180 $this->privCalculateStoredFilename($v_descr, $p_options);2181 2182 // ----- Add the descriptor in result list2183 $v_result_list[sizeof($v_result_list)] = $v_descr;2184 2185 // ----- Look for folder2186 if ($v_descr['type'] == 'folder') {2187 // ----- List of items in folder2188 $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 filename2200 $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;2201 2202 // ----- Look for different stored filename2203 // Because the name of the folder was changed, the name of the2204 // files/sub-folders also change2205 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 mode2222 }2223 2224 // ----- Expand each element of the list2225 if ($v_dirlist_nb != 0) {2226 // ----- Expand2227 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 list2233 //--(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 array2242 unset($v_dirlist_descr);2243 }2244 }2245 2246 // ----- Get the result list2247 $p_filedescr_list = $v_result_list;2248 2249 // ----- Return2250 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2251 return $v_result;2122 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", ""); 2123 $v_result=1; 2124 2125 // ----- Create a result list 2126 $v_result_list = array(); 2127 2128 // ----- Look each entry 2129 for ($i=0; $i<sizeof($p_filedescr_list); $i++) { 2130 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for file ".$i."."); 2131 2132 // ----- Get filedescr 2133 $v_descr = $p_filedescr_list[$i]; 2134 2135 // ----- Reduce the filename 2136 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'"); 2137 $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); 2138 $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); 2139 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'"); 2140 2141 // ----- Look for real file or folder 2142 if (file_exists($v_descr['filename'])) { 2143 if (@is_file($v_descr['filename'])) { 2144 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file"); 2145 $v_descr['type'] = 'file'; 2146 } 2147 else if (@is_dir($v_descr['filename'])) { 2148 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder"); 2149 $v_descr['type'] = 'folder'; 2150 } 2151 else if (@is_link($v_descr['filename'])) { 2152 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link"); 2153 // skip 2154 continue; 2155 } 2156 else { 2157 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type"); 2158 // skip 2159 continue; 2160 } 2161 } 2162 2163 // ----- Look for string added as file 2164 else if (isset($v_descr['content'])) { 2165 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a string added as a file"); 2166 $v_descr['type'] = 'virtual_file'; 2167 } 2168 2169 // ----- Missing file 2170 else { 2171 // ----- Error log 2172 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exist"); 2173 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist"); 2174 2175 // ----- Return 2176 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2177 return PclZip::errorCode(); 2178 } 2179 2180 // ----- Calculate the stored filename 2181 $this->privCalculateStoredFilename($v_descr, $p_options); 2182 2183 // ----- Add the descriptor in result list 2184 $v_result_list[sizeof($v_result_list)] = $v_descr; 2185 2186 // ----- Look for folder 2187 if ($v_descr['type'] == 'folder') { 2188 // ----- List of items in folder 2189 $v_dirlist_descr = array(); 2190 $v_dirlist_nb = 0; 2191 if ($v_folder_handler = @opendir($v_descr['filename'])) { 2192 while (($v_item_handler = @readdir($v_folder_handler)) !== false) { 2193 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory"); 2194 2195 // ----- Skip '.' and '..' 2196 if (($v_item_handler == '.') || ($v_item_handler == '..')) { 2197 continue; 2198 } 2199 2200 // ----- Compose the full filename 2201 $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; 2202 2203 // ----- Look for different stored filename 2204 // Because the name of the folder was changed, the name of the 2205 // files/sub-folders also change 2206 if ($v_descr['stored_filename'] != $v_descr['filename']) { 2207 if ($v_descr['stored_filename'] != '') { 2208 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; 2209 } 2210 else { 2211 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; 2212 } 2213 } 2214 2215 $v_dirlist_nb++; 2216 } 2217 2218 @closedir($v_folder_handler); 2219 } 2220 else { 2221 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped."); 2222 // TBC : unable to open folder in read mode 2223 } 2224 2225 // ----- Expand each element of the list 2226 if ($v_dirlist_nb != 0) { 2227 // ----- Expand 2228 if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { 2229 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2230 return $v_result; 2231 } 2232 2233 // ----- Concat the resulting list 2234 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')"); 2235 $v_result_list = array_merge($v_result_list, $v_dirlist_descr); 2236 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'"); 2237 } 2238 else { 2239 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand."); 2240 } 2241 2242 // ----- Free local array 2243 unset($v_dirlist_descr); 2244 } 2245 } 2246 2247 // ----- Get the result list 2248 $p_filedescr_list = $v_result_list; 2249 2250 // ----- Return 2251 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2252 return $v_result; 2252 2253 } 2253 2254 // -------------------------------------------------------------------------------- … … 2261 2262 function privCreate($p_filedescr_list, &$p_result_list, &$p_options) 2262 2263 { 2263 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list");2264 $v_result=1;2265 $v_list_detail = array();2266 2267 // ----- Magic quotes trick2268 $this->privDisableMagicQuotes();2269 2270 // ----- Open the file in write mode2271 if (($v_result = $this->privOpenFd('wb')) != 1)2272 {2273 // ----- Return2274 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2275 return $v_result;2276 }2277 2278 // ----- Add the list of files2279 $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);2280 2281 // ----- Close2282 $this->privCloseFd();2283 2284 // ----- Magic quotes trick2285 $this->privSwapBackMagicQuotes();2286 2287 // ----- Return2288 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2289 return $v_result;2264 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list"); 2265 $v_result=1; 2266 $v_list_detail = array(); 2267 2268 // ----- Magic quotes trick 2269 $this->privDisableMagicQuotes(); 2270 2271 // ----- Open the file in write mode 2272 if (($v_result = $this->privOpenFd('wb')) != 1) 2273 { 2274 // ----- Return 2275 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2276 return $v_result; 2277 } 2278 2279 // ----- Add the list of files 2280 $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options); 2281 2282 // ----- Close 2283 $this->privCloseFd(); 2284 2285 // ----- Magic quotes trick 2286 $this->privSwapBackMagicQuotes(); 2287 2288 // ----- Return 2289 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2290 return $v_result; 2290 2291 } 2291 2292 // -------------------------------------------------------------------------------- … … 2299 2300 function privAdd($p_filedescr_list, &$p_result_list, &$p_options) 2300 2301 { 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 empty2306 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 create2311 $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);2312 2313 // ----- Return2314 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2315 return $v_result;2316 }2317 // ----- Magic quotes trick2318 $this->privDisableMagicQuotes();2319 2320 // ----- Open the zip file2321 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");2322 if (($v_result=$this->privOpenFd('rb')) != 1)2323 {2324 // ----- Magic quotes trick2325 $this->privSwapBackMagicQuotes();2326 2327 // ----- Return2328 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2329 return $v_result;2330 }2331 2332 // ----- Read the central directory informations2333 $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 File2343 //--(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 file2348 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';2349 2350 // ----- Open the temporary file in write mode2351 //--(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 // ----- Return2360 //--(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 file2365 // TBC : Here I should better append the file and go back to erase the central dir2366 $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 descriptor2377 // Here is a trick : I swap the temporary fd with the zip fd, in order to use2378 // the following methods on the temporary fil and not the real archive2379 $v_swap = $this->zip_fd;2380 $this->zip_fd = $v_zip_temp_fd;2381 $v_zip_temp_fd = $v_swap;2382 2383 // ----- Add the files2384 $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 // ----- Return2393 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2394 return $v_result;2395 }2396 2397 // ----- Store the offset of the central dir2398 $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 archive2402 $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 header2413 for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)2414 {2415 // ----- Create the file header2416 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 // ----- Return2424 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2425 return $v_result;2426 }2427 $v_count++;2428 }2429 2430 // ----- Transform the header to a 'usable' info2431 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);2432 }2433 2434 // ----- Zip file comment2435 $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 header2447 $v_size = @ftell($this->zip_fd)-$v_offset;2448 2449 // ----- Create the central dir footer2450 if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)2451 {2452 // ----- Reset the file list2453 unset($v_header_list);2454 $this->privSwapBackMagicQuotes();2455 2456 // ----- Return2457 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2458 return $v_result;2459 }2460 2461 // ----- Swap back the file descriptor2462 $v_swap = $this->zip_fd;2463 $this->zip_fd = $v_zip_temp_fd;2464 $v_zip_temp_fd = $v_swap;2465 2466 // ----- Close2467 $this->privCloseFd();2468 2469 // ----- Close the temporary file2470 @fclose($v_zip_temp_fd);2471 2472 // ----- Magic quotes trick2473 $this->privSwapBackMagicQuotes();2474 2475 // ----- Delete the zip file2476 // TBC : I should test the result ...2477 @unlink($this->zipname);2478 2479 // ----- Rename the temporary file2480 // TBC : I should test the result ...2481 //@rename($v_zip_temp_name, $this->zipname);2482 PclZipUtilRename($v_zip_temp_name, $this->zipname);2483 2484 // ----- Return2485 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2486 return $v_result;2302 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list"); 2303 $v_result=1; 2304 $v_list_detail = array(); 2305 2306 // ----- Look if the archive exists or is empty 2307 if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) 2308 { 2309 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it."); 2310 2311 // ----- Do a create 2312 $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); 2313 2314 // ----- Return 2315 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2316 return $v_result; 2317 } 2318 // ----- Magic quotes trick 2319 $this->privDisableMagicQuotes(); 2320 2321 // ----- Open the zip file 2322 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 2323 if (($v_result=$this->privOpenFd('rb')) != 1) 2324 { 2325 // ----- Magic quotes trick 2326 $this->privSwapBackMagicQuotes(); 2327 2328 // ----- Return 2329 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2330 return $v_result; 2331 } 2332 2333 // ----- Read the central directory informations 2334 $v_central_dir = array(); 2335 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 2336 { 2337 $this->privCloseFd(); 2338 $this->privSwapBackMagicQuotes(); 2339 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2340 return $v_result; 2341 } 2342 2343 // ----- Go to beginning of File 2344 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); 2345 @rewind($this->zip_fd); 2346 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); 2347 2348 // ----- Creates a temporay file 2349 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; 2350 2351 // ----- Open the temporary file in write mode 2352 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 2353 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) 2354 { 2355 $this->privCloseFd(); 2356 $this->privSwapBackMagicQuotes(); 2357 2358 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); 2359 2360 // ----- Return 2361 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2362 return PclZip::errorCode(); 2363 } 2364 2365 // ----- Copy the files from the archive to the temporary file 2366 // TBC : Here I should better append the file and go back to erase the central dir 2367 $v_size = $v_central_dir['offset']; 2368 while ($v_size != 0) 2369 { 2370 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 2371 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 2372 $v_buffer = fread($this->zip_fd, $v_read_size); 2373 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 2374 $v_size -= $v_read_size; 2375 } 2376 2377 // ----- Swap the file descriptor 2378 // Here is a trick : I swap the temporary fd with the zip fd, in order to use 2379 // the following methods on the temporary fil and not the real archive 2380 $v_swap = $this->zip_fd; 2381 $this->zip_fd = $v_zip_temp_fd; 2382 $v_zip_temp_fd = $v_swap; 2383 2384 // ----- Add the files 2385 $v_header_list = array(); 2386 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) 2387 { 2388 fclose($v_zip_temp_fd); 2389 $this->privCloseFd(); 2390 @unlink($v_zip_temp_name); 2391 $this->privSwapBackMagicQuotes(); 2392 2393 // ----- Return 2394 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2395 return $v_result; 2396 } 2397 2398 // ----- Store the offset of the central dir 2399 $v_offset = @ftell($this->zip_fd); 2400 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset"); 2401 2402 // ----- Copy the block of file headers from the old archive 2403 $v_size = $v_central_dir['size']; 2404 while ($v_size != 0) 2405 { 2406 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 2407 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 2408 $v_buffer = @fread($v_zip_temp_fd, $v_read_size); 2409 @fwrite($this->zip_fd, $v_buffer, $v_read_size); 2410 $v_size -= $v_read_size; 2411 } 2412 2413 // ----- Create the Central Dir files header 2414 for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++) 2415 { 2416 // ----- Create the file header 2417 if ($v_header_list[$i]['status'] == 'ok') { 2418 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { 2419 fclose($v_zip_temp_fd); 2420 $this->privCloseFd(); 2421 @unlink($v_zip_temp_name); 2422 $this->privSwapBackMagicQuotes(); 2423 2424 // ----- Return 2425 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2426 return $v_result; 2427 } 2428 $v_count++; 2429 } 2430 2431 // ----- Transform the header to a 'usable' info 2432 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); 2433 } 2434 2435 // ----- Zip file comment 2436 $v_comment = $v_central_dir['comment']; 2437 if (isset($p_options[PCLZIP_OPT_COMMENT])) { 2438 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; 2439 } 2440 if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) { 2441 $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT]; 2442 } 2443 if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) { 2444 $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment; 2445 } 2446 2447 // ----- Calculate the size of the central header 2448 $v_size = @ftell($this->zip_fd)-$v_offset; 2449 2450 // ----- Create the central dir footer 2451 if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) 2452 { 2453 // ----- Reset the file list 2454 unset($v_header_list); 2455 $this->privSwapBackMagicQuotes(); 2456 2457 // ----- Return 2458 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2459 return $v_result; 2460 } 2461 2462 // ----- Swap back the file descriptor 2463 $v_swap = $this->zip_fd; 2464 $this->zip_fd = $v_zip_temp_fd; 2465 $v_zip_temp_fd = $v_swap; 2466 2467 // ----- Close 2468 $this->privCloseFd(); 2469 2470 // ----- Close the temporary file 2471 @fclose($v_zip_temp_fd); 2472 2473 // ----- Magic quotes trick 2474 $this->privSwapBackMagicQuotes(); 2475 2476 // ----- Delete the zip file 2477 // TBC : I should test the result ... 2478 @unlink($this->zipname); 2479 2480 // ----- Rename the temporary file 2481 // TBC : I should test the result ... 2482 //@rename($v_zip_temp_name, $this->zipname); 2483 PclZipUtilRename($v_zip_temp_name, $this->zipname); 2484 2485 // ----- Return 2486 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2487 return $v_result; 2487 2488 } 2488 2489 // -------------------------------------------------------------------------------- … … 2495 2496 function privOpenFd($p_mode) 2496 2497 { 2497 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOpenFd", 'mode='.$p_mode);2498 $v_result=1;2499 2500 // ----- Look if already open2501 if ($this->zip_fd != 0)2502 {2503 // ----- Error log2504 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');2505 2506 // ----- Return2507 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());2508 return PclZip::errorCode();2509 }2510 2511 // ----- Open the zip file2512 //--(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 log2516 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');2517 2518 // ----- Return2519 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());2520 return PclZip::errorCode();2521 }2522 2523 // ----- Return2524 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2525 return $v_result;2498 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOpenFd", 'mode='.$p_mode); 2499 $v_result=1; 2500 2501 // ----- Look if already open 2502 if ($this->zip_fd != 0) 2503 { 2504 // ----- Error log 2505 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); 2506 2507 // ----- Return 2508 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2509 return PclZip::errorCode(); 2510 } 2511 2512 // ----- Open the zip file 2513 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Open file in '.$p_mode.' mode'); 2514 if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) 2515 { 2516 // ----- Error log 2517 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); 2518 2519 // ----- Return 2520 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2521 return PclZip::errorCode(); 2522 } 2523 2524 // ----- Return 2525 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2526 return $v_result; 2526 2527 } 2527 2528 // -------------------------------------------------------------------------------- … … 2534 2535 function privCloseFd() 2535 2536 { 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 // ----- Return2544 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2545 return $v_result;2537 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCloseFd", ""); 2538 $v_result=1; 2539 2540 if ($this->zip_fd != 0) 2541 @fclose($this->zip_fd); 2542 $this->zip_fd = 0; 2543 2544 // ----- Return 2545 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2546 return $v_result; 2546 2547 } 2547 2548 // -------------------------------------------------------------------------------- … … 2563 2564 function privAddList($p_filedescr_list, &$p_result_list, &$p_options) 2564 2565 { 2565 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list");2566 $v_result=1;2567 2568 // ----- Add the files2569 $v_header_list = array();2570 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)2571 {2572 // ----- Return2573 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2574 return $v_result;2575 }2576 2577 // ----- Store the offset of the central dir2578 $v_offset = @ftell($this->zip_fd);2579 2580 // ----- Create the Central Dir files header2581 for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)2582 {2583 // ----- Create the file header2584 if ($v_header_list[$i]['status'] == 'ok') {2585 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {2586 // ----- Return2587 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2588 return $v_result;2589 }2590 $v_count++;2591 }2592 2593 // ----- Transform the header to a 'usable' info2594 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);2595 }2596 2597 // ----- Zip file comment2598 $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 header2604 $v_size = @ftell($this->zip_fd)-$v_offset;2605 2606 // ----- Create the central dir footer2607 if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)2608 {2609 // ----- Reset the file list2610 unset($v_header_list);2611 2612 // ----- Return2613 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2614 return $v_result;2615 }2616 2617 // ----- Return2618 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2619 return $v_result;2566 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list"); 2567 $v_result=1; 2568 2569 // ----- Add the files 2570 $v_header_list = array(); 2571 if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) 2572 { 2573 // ----- Return 2574 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2575 return $v_result; 2576 } 2577 2578 // ----- Store the offset of the central dir 2579 $v_offset = @ftell($this->zip_fd); 2580 2581 // ----- Create the Central Dir files header 2582 for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++) 2583 { 2584 // ----- Create the file header 2585 if ($v_header_list[$i]['status'] == 'ok') { 2586 if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { 2587 // ----- Return 2588 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2589 return $v_result; 2590 } 2591 $v_count++; 2592 } 2593 2594 // ----- Transform the header to a 'usable' info 2595 $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); 2596 } 2597 2598 // ----- Zip file comment 2599 $v_comment = ''; 2600 if (isset($p_options[PCLZIP_OPT_COMMENT])) { 2601 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; 2602 } 2603 2604 // ----- Calculate the size of the central header 2605 $v_size = @ftell($this->zip_fd)-$v_offset; 2606 2607 // ----- Create the central dir footer 2608 if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) 2609 { 2610 // ----- Reset the file list 2611 unset($v_header_list); 2612 2613 // ----- Return 2614 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2615 return $v_result; 2616 } 2617 2618 // ----- Return 2619 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2620 return $v_result; 2620 2621 } 2621 2622 // -------------------------------------------------------------------------------- … … 2626 2627 // Parameters : 2627 2628 // $p_filedescr_list : An array containing the file description 2628 // or directory names to add in the zip2629 // or directory names to add in the zip 2629 2630 // $p_result_list : list of added files with their properties (specially the status field) 2630 2631 // Return Values : … … 2632 2633 function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) 2633 2634 { 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 list2639 $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 files2643 for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {2644 // ----- Format the filename2645 $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 names2651 // 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 filename2658 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 option2667 // or a dir with all its path removed2668 // 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 file2678 $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 infos2686 $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 // ----- Return2692 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);2693 return $v_result;2635 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "filedescr_list"); 2636 $v_result=1; 2637 $v_header = array(); 2638 2639 // ----- Recuperate the current number of elt in list 2640 $v_nb = sizeof($p_result_list); 2641 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Before add, list have ".$v_nb." elements"); 2642 2643 // ----- Loop on the files 2644 for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { 2645 // ----- Format the filename 2646 $p_filedescr_list[$j]['filename'] 2647 = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); 2648 2649 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'"); 2650 2651 // ----- Skip empty file names 2652 // TBC : Can this be possible ? not checked in DescrParseAtt ? 2653 if ($p_filedescr_list[$j]['filename'] == "") { 2654 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Skip empty filename"); 2655 continue; 2656 } 2657 2658 // ----- Check the filename 2659 if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') 2660 && (!file_exists($p_filedescr_list[$j]['filename']))) { 2661 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); 2662 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); 2663 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2664 return PclZip::errorCode(); 2665 } 2666 2667 // ----- Look if it is a file or a dir with no all path remove option 2668 // or a dir with all its path removed 2669 // if ( (is_file($p_filedescr_list[$j]['filename'])) 2670 // || ( is_dir($p_filedescr_list[$j]['filename']) 2671 if ( ($p_filedescr_list[$j]['type'] == 'file') 2672 || ($p_filedescr_list[$j]['type'] == 'virtual_file') 2673 || ( ($p_filedescr_list[$j]['type'] == 'folder') 2674 && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) 2675 || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) 2676 ) { 2677 2678 // ----- Add the file 2679 $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header, 2680 $p_options); 2681 if ($v_result != 1) { 2682 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2683 return $v_result; 2684 } 2685 2686 // ----- Store the file infos 2687 $p_result_list[$v_nb++] = $v_header; 2688 } 2689 } 2690 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "After add, list have ".$v_nb." elements"); 2691 2692 // ----- Return 2693 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2694 return $v_result; 2694 2695 } 2695 2696 // -------------------------------------------------------------------------------- … … 2703 2704 function privAddFile($p_filedescr, &$p_header, &$p_options) 2704 2705 { 2705 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'");2706 $v_result=1;2707 2708 // ----- Working variable2709 $p_filename = $p_filedescr['filename'];2710 2711 // TBC : Already done in the fileAtt check ... ?2712 if ($p_filename == "") {2713 // ----- Error log2714 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");2715 2716 // ----- Return2717 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());2718 return PclZip::errorCode();2719 }2706 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'"); 2707 $v_result=1; 2708 2709 // ----- Working variable 2710 $p_filename = $p_filedescr['filename']; 2711 2712 // TBC : Already done in the fileAtt check ... ? 2713 if ($p_filename == "") { 2714 // ----- Error log 2715 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); 2716 2717 // ----- Return 2718 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2719 return PclZip::errorCode(); 2720 } 2720 2721 2721 // ----- Look for a stored different filename2722 /* TBC : Removed2723 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 properties2734 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 file2754 if ($p_filedescr['type']=='file') {2755 $p_header['external'] = 0x00000000;2756 $p_header['size'] = filesize($p_filename);2757 }2758 2759 // ----- Look for regular folder2760 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 file2767 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 filetime2775 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 comment2786 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 callback2796 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 information2800 $v_local_header = array();2801 $this->privConvertHeader2FileInfo($p_header, $v_local_header);2802 2803 // ----- Call the callback2804 // Here I do not use call_user_func() because I need to send a reference to the2805 // 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 status2809 $p_header['status'] = "skipped";2810 $v_result = 1;2811 }2812 2813 // ----- Update the informations2814 // Only some fields can be modified2815 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 filename2822 if ($p_header['stored_filename'] == "") {2823 $p_header['status'] = "filtered";2824 }2825 2826 // ----- Check the path length2827 if (strlen($p_header['stored_filename']) > 0xFF) {2828 $p_header['status'] = 'filename_too_long';2829 }2830 2831 // ----- Look if no error, or file not skipped2832 if ($p_header['status'] == 'ok') {2833 2834 // ----- Look for a file2835 if ($p_filedescr['type'] == 'file') {2836 // ----- Look for using temporary file to zip2837 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 algo2848 else {2849 2850 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file");2851 2852 // ----- Open the source file2853 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 content2860 $v_content = @fread($v_file, $p_header['size']);2861 2862 // ----- Close the file2863 @fclose($v_file);2864 2865 // ----- Calculate the CRC2866 $p_header['crc'] = @crc32($v_content);2867 2868 // ----- Look for no compression2869 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {2870 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed");2871 // ----- Set header parameters2872 $p_header['compressed_size'] = $p_header['size'];2873 $p_header['compression'] = 0;2874 }2875 2876 // ----- Look for normal compression2877 else {2878 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed");2879 // ----- Compress the content2880 $v_content = @gzdeflate($v_content);2881 2882 // ----- Set header parameters2883 $p_header['compressed_size'] = strlen($v_content);2884 $p_header['compression'] = 8;2885 }2886 2887 // ----- Look for encryption2888 /*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 header2894 $v_header = 'xxxxxxxxxxxx';2895 $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed,2896 $p_header['compressed_size'],2897 $v_header,2722 // ----- Look for a stored different filename 2723 /* TBC : Removed 2724 if (isset($p_filedescr['stored_filename'])) { 2725 $v_stored_filename = $p_filedescr['stored_filename']; 2726 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is NOT the same "'.$v_stored_filename.'"'); 2727 } 2728 else { 2729 $v_stored_filename = $p_filedescr['stored_filename']; 2730 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is the same'); 2731 } 2732 */ 2733 2734 // ----- Set the file properties 2735 clearstatcache(); 2736 $p_header['version'] = 20; 2737 $p_header['version_extracted'] = 10; 2738 $p_header['flag'] = 0; 2739 $p_header['compression'] = 0; 2740 $p_header['crc'] = 0; 2741 $p_header['compressed_size'] = 0; 2742 $p_header['filename_len'] = strlen($p_filename); 2743 $p_header['extra_len'] = 0; 2744 $p_header['disk'] = 0; 2745 $p_header['internal'] = 0; 2746 $p_header['offset'] = 0; 2747 $p_header['filename'] = $p_filename; 2748 // TBC : Removed $p_header['stored_filename'] = $v_stored_filename; 2749 $p_header['stored_filename'] = $p_filedescr['stored_filename']; 2750 $p_header['extra'] = ''; 2751 $p_header['status'] = 'ok'; 2752 $p_header['index'] = -1; 2753 2754 // ----- Look for regular file 2755 if ($p_filedescr['type']=='file') { 2756 $p_header['external'] = 0x00000000; 2757 $p_header['size'] = filesize($p_filename); 2758 } 2759 2760 // ----- Look for regular folder 2761 else if ($p_filedescr['type']=='folder') { 2762 $p_header['external'] = 0x00000010; 2763 $p_header['mtime'] = filemtime($p_filename); 2764 $p_header['size'] = filesize($p_filename); 2765 } 2766 2767 // ----- Look for virtual file 2768 else if ($p_filedescr['type'] == 'virtual_file') { 2769 $p_header['external'] = 0x00000000; 2770 $p_header['size'] = strlen($p_filedescr['content']); 2771 } 2772 2773 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header external extension '".sprintf("0x%X",$p_header['external'])."'"); 2774 2775 // ----- Look for filetime 2776 if (isset($p_filedescr['mtime'])) { 2777 $p_header['mtime'] = $p_filedescr['mtime']; 2778 } 2779 else if ($p_filedescr['type'] == 'virtual_file') { 2780 $p_header['mtime'] = time(); 2781 } 2782 else { 2783 $p_header['mtime'] = filemtime($p_filename); 2784 } 2785 2786 // ------ Look for file comment 2787 if (isset($p_filedescr['comment'])) { 2788 $p_header['comment_len'] = strlen($p_filedescr['comment']); 2789 $p_header['comment'] = $p_filedescr['comment']; 2790 } 2791 else { 2792 $p_header['comment_len'] = 0; 2793 $p_header['comment'] = ''; 2794 } 2795 2796 // ----- Look for pre-add callback 2797 if (isset($p_options[PCLZIP_CB_PRE_ADD])) { 2798 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_ADD]."()') is defined for the extraction"); 2799 2800 // ----- Generate a local information 2801 $v_local_header = array(); 2802 $this->privConvertHeader2FileInfo($p_header, $v_local_header); 2803 2804 // ----- Call the callback 2805 // Here I do not use call_user_func() because I need to send a reference to the 2806 // header. 2807 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);'); 2808 if ($v_result == 0) { 2809 // ----- Change the file status 2810 $p_header['status'] = "skipped"; 2811 $v_result = 1; 2812 } 2813 2814 // ----- Update the informations 2815 // Only some fields can be modified 2816 if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { 2817 $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); 2818 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New stored filename is '".$p_header['stored_filename']."'"); 2819 } 2820 } 2821 2822 // ----- Look for empty stored filename 2823 if ($p_header['stored_filename'] == "") { 2824 $p_header['status'] = "filtered"; 2825 } 2826 2827 // ----- Check the path length 2828 if (strlen($p_header['stored_filename']) > 0xFF) { 2829 $p_header['status'] = 'filename_too_long'; 2830 } 2831 2832 // ----- Look if no error, or file not skipped 2833 if ($p_header['status'] == 'ok') { 2834 2835 // ----- Look for a file 2836 if ($p_filedescr['type'] == 'file') { 2837 // ----- Look for using temporary file to zip 2838 if ( (!isset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_OFF])) 2839 && (isset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_ON]) 2840 || (isset($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD]) 2841 && ($p_options[PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { 2842 $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); 2843 if ($v_result >= PCLZIP_ERR_NO_ERROR) { 2844 return $v_result; 2845 } 2846 } 2847 2848 // ----- Use "in memory" zip algo 2849 else { 2850 2851 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file"); 2852 2853 // ----- Open the source file 2854 if (($v_file = @fopen($p_filename, "rb")) == 0) { 2855 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); 2856 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2857 return PclZip::errorCode(); 2858 } 2859 2860 // ----- Read the file content 2861 $v_content = @fread($v_file, $p_header['size']); 2862 2863 // ----- Close the file 2864 @fclose($v_file); 2865 2866 // ----- Calculate the CRC 2867 $p_header['crc'] = @crc32($v_content); 2868 2869 // ----- Look for no compression 2870 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { 2871 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed"); 2872 // ----- Set header parameters 2873 $p_header['compressed_size'] = $p_header['size']; 2874 $p_header['compression'] = 0; 2875 } 2876 2877 // ----- Look for normal compression 2878 else { 2879 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed"); 2880 // ----- Compress the content 2881 $v_content = @gzdeflate($v_content); 2882 2883 // ----- Set header parameters 2884 $p_header['compressed_size'] = strlen($v_content); 2885 $p_header['compression'] = 8; 2886 } 2887 2888 // ----- Look for encryption 2889 /* 2890 if ((isset($p_options[PCLZIP_OPT_CRYPT])) 2891 && ($p_options[PCLZIP_OPT_CRYPT] != "")) { 2892 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ...."); 2893 2894 // Should be a random header 2895 $v_header = 'xxxxxxxxxxxx'; 2896 $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed, 2897 $p_header['compressed_size'], 2898 $v_header, 2898 2899 $p_header['crc'], 2899 2900 "test"); 2900 2901 2901 $p_header['compressed_size'] += 12;2902 $p_header['flag'] = 1;2903 2904 // ----- Add the header to the data2905 $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 generation2911 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) content2918 @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 CRC2931 $p_header['crc'] = @crc32($v_content);2932 2933 // ----- Look for no compression2934 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {2935 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed");2936 // ----- Set header parameters2937 $p_header['compressed_size'] = $p_header['size'];2938 $p_header['compression'] = 0;2939 }2940 2941 // ----- Look for normal compression2942 else {2943 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed");2944 // ----- Compress the content2945 $v_content = @gzdeflate($v_content);2946 2947 // ----- Set header parameters2948 $p_header['compressed_size'] = strlen($v_content);2949 $p_header['compression'] = 8;2950 }2951 2952 // ----- Look for encryption2953 /*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 header2959 $v_header = 'xxxxxxxxxxxx';2960 $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed,2961 $p_header['compressed_size'],2962 $v_header,2902 $p_header['compressed_size'] += 12; 2903 $p_header['flag'] = 1; 2904 2905 // ----- Add the header to the data 2906 $v_content_compressed = $v_header.$v_content_compressed; 2907 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed).""); 2908 } 2909 */ 2910 2911 // ----- Call the header generation 2912 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { 2913 @fclose($v_file); 2914 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2915 return $v_result; 2916 } 2917 2918 // ----- Write the compressed (or not) content 2919 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); 2920 2921 } 2922 2923 } 2924 2925 // ----- Look for a virtual file (a file from string) 2926 else if ($p_filedescr['type'] == 'virtual_file') { 2927 2928 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Add by string"); 2929 $v_content = $p_filedescr['content']; 2930 2931 // ----- Calculate the CRC 2932 $p_header['crc'] = @crc32($v_content); 2933 2934 // ----- Look for no compression 2935 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { 2936 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed"); 2937 // ----- Set header parameters 2938 $p_header['compressed_size'] = $p_header['size']; 2939 $p_header['compression'] = 0; 2940 } 2941 2942 // ----- Look for normal compression 2943 else { 2944 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed"); 2945 // ----- Compress the content 2946 $v_content = @gzdeflate($v_content); 2947 2948 // ----- Set header parameters 2949 $p_header['compressed_size'] = strlen($v_content); 2950 $p_header['compression'] = 8; 2951 } 2952 2953 // ----- Look for encryption 2954 /* 2955 if ((isset($p_options[PCLZIP_OPT_CRYPT])) 2956 && ($p_options[PCLZIP_OPT_CRYPT] != "")) { 2957 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ...."); 2958 2959 // Should be a random header 2960 $v_header = 'xxxxxxxxxxxx'; 2961 $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed, 2962 $p_header['compressed_size'], 2963 $v_header, 2963 2964 $p_header['crc'], 2964 2965 "test"); 2965 2966 2966 $p_header['compressed_size'] += 12;2967 $p_header['flag'] = 1;2968 2969 // ----- Add the header to the data2970 $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 generation2976 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) content2983 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);2984 }2985 2986 // ----- Look for a directory2987 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 properties2995 $p_header['size'] = 0;2996 //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked2997 $p_header['external'] = 0x00000010; // Value for a folder : to be checked2998 2999 // ----- Call the header generation3000 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 callback3009 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 information3013 $v_local_header = array();3014 $this->privConvertHeader2FileInfo($p_header, $v_local_header);3015 3016 // ----- Call the callback3017 // Here I do not use call_user_func() because I need to send a reference to the3018 // header.3019 eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');3020 if ($v_result == 0) {3021 // ----- Ignored3022 $v_result = 1;3023 }3024 3025 // ----- Update the informations3026 // Nothing can be modified3027 }3028 3029 // ----- Return3030 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3031 return $v_result;2967 $p_header['compressed_size'] += 12; 2968 $p_header['flag'] = 1; 2969 2970 // ----- Add the header to the data 2971 $v_content_compressed = $v_header.$v_content_compressed; 2972 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed).""); 2973 } 2974 */ 2975 2976 // ----- Call the header generation 2977 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { 2978 @fclose($v_file); 2979 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2980 return $v_result; 2981 } 2982 2983 // ----- Write the compressed (or not) content 2984 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); 2985 } 2986 2987 // ----- Look for a directory 2988 else if ($p_filedescr['type'] == 'folder') { 2989 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder"); 2990 // ----- Look for directory last '/' 2991 if (@substr($p_header['stored_filename'], -1) != '/') { 2992 $p_header['stored_filename'] .= '/'; 2993 } 2994 2995 // ----- Set the file properties 2996 $p_header['size'] = 0; 2997 //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked 2998 $p_header['external'] = 0x00000010; // Value for a folder : to be checked 2999 3000 // ----- Call the header generation 3001 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) 3002 { 3003 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3004 return $v_result; 3005 } 3006 } 3007 } 3008 3009 // ----- Look for post-add callback 3010 if (isset($p_options[PCLZIP_CB_POST_ADD])) { 3011 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_ADD]."()') is defined for the extraction"); 3012 3013 // ----- Generate a local information 3014 $v_local_header = array(); 3015 $this->privConvertHeader2FileInfo($p_header, $v_local_header); 3016 3017 // ----- Call the callback 3018 // Here I do not use call_user_func() because I need to send a reference to the 3019 // header. 3020 eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);'); 3021 if ($v_result == 0) { 3022 // ----- Ignored 3023 $v_result = 1; 3024 } 3025 3026 // ----- Update the informations 3027 // Nothing can be modified 3028 } 3029 3030 // ----- Return 3031 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3032 return $v_result; 3032 3033 } 3033 3034 // -------------------------------------------------------------------------------- … … 3041 3042 function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) 3042 3043 { 3043 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileUsingTempFile", "filename='".$p_filedescr['filename']."'");3044 $v_result=PCLZIP_ERR_NO_ERROR;3045 3046 // ----- Working variable3047 $p_filename = $p_filedescr['filename'];3048 3049 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file");3050 3051 // ----- Open the source file3052 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 file3059 $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 blocks3068 $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 file3079 @fclose($v_file);3080 @gzclose($v_file_compressed);3081 3082 // ----- Check the minimum file size3083 //--(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 attributes3091 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 header3098 $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 parameters3102 //--(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 footer3112 //--(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 attributes3120 $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 file3127 @fclose($v_file_compressed);3128 3129 // ----- Call the header generation3130 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 data3136 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 blocks3144 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 file3159 @fclose($v_file_compressed);3160 3161 // ----- Unlink the temporary file3162 @unlink($v_gzip_temp_name);3163 3164 // ----- Return3165 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3166 return $v_result;3044 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileUsingTempFile", "filename='".$p_filedescr['filename']."'"); 3045 $v_result=PCLZIP_ERR_NO_ERROR; 3046 3047 // ----- Working variable 3048 $p_filename = $p_filedescr['filename']; 3049 3050 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file"); 3051 3052 // ----- Open the source file 3053 if (($v_file = @fopen($p_filename, "rb")) == 0) { 3054 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); 3055 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3056 return PclZip::errorCode(); 3057 } 3058 3059 // ----- Creates a compressed temporary file 3060 $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; 3061 if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { 3062 fclose($v_file); 3063 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); 3064 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3065 return PclZip::errorCode(); 3066 } 3067 3068 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks 3069 $v_size = filesize($p_filename); 3070 while ($v_size != 0) { 3071 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 3072 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes"); 3073 $v_buffer = fread($v_file, $v_read_size); 3074 //$v_binary_data = pack('a'.$v_read_size, $v_buffer); 3075 @gzputs($v_file_compressed, $v_buffer, $v_read_size); 3076 $v_size -= $v_read_size; 3077 } 3078 3079 // ----- Close the file 3080 @fclose($v_file); 3081 @gzclose($v_file_compressed); 3082 3083 // ----- Check the minimum file size 3084 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "gzip file size ".filesize($v_gzip_temp_name)); 3085 if (filesize($v_gzip_temp_name) < 18) { 3086 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); 3087 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3088 return PclZip::errorCode(); 3089 } 3090 3091 // ----- Extract the compressed attributes 3092 if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { 3093 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); 3094 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3095 return PclZip::errorCode(); 3096 } 3097 3098 // ----- Read the gzip file header 3099 $v_binary_data = @fread($v_file_compressed, 10); 3100 $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data); 3101 3102 // ----- Check some parameters 3103 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[id1]='.bin2hex($v_data_header['id1'])); 3104 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[id2]='.bin2hex($v_data_header['id2'])); 3105 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[cm]='.bin2hex($v_data_header['cm'])); 3106 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[flag]='.bin2hex($v_data_header['flag'])); 3107 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[mtime]='.$v_data_header['mtime']); 3108 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[xfl]='.bin2hex($v_data_header['xfl'])); 3109 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[os]='.bin2hex($v_data_header['os'])); 3110 $v_data_header['os'] = bin2hex($v_data_header['os']); 3111 3112 // ----- Read the gzip file footer 3113 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position after header ".ftell($v_file_compressed)); 3114 @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8); 3115 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position at beginning of footer ".ftell($v_file_compressed)); 3116 $v_binary_data = @fread($v_file_compressed, 8); 3117 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position after footer ".ftell($v_file_compressed)); 3118 $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data); 3119 3120 // ----- Set the attributes 3121 $p_header['compression'] = ord($v_data_header['cm']); 3122 //$p_header['mtime'] = $v_data_header['mtime']; 3123 $p_header['crc'] = $v_data_footer['crc']; 3124 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Compressed size ".(filesize($v_gzip_temp_name)-18)); 3125 $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18; 3126 3127 // ----- Close the file 3128 @fclose($v_file_compressed); 3129 3130 // ----- Call the header generation 3131 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { 3132 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3133 return $v_result; 3134 } 3135 3136 // ----- Add the compressed data 3137 if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) 3138 { 3139 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); 3140 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3141 return PclZip::errorCode(); 3142 } 3143 3144 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks 3145 fseek($v_file_compressed, 10); 3146 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position before reading compressed data ".ftell($v_file_compressed)); 3147 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, ' '.$p_header['compressed_size'].' bytes to read'); 3148 $v_size = $p_header['compressed_size']; 3149 while ($v_size != 0) 3150 { 3151 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 3152 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes"); 3153 $v_buffer = fread($v_file_compressed, $v_read_size); 3154 //$v_binary_data = pack('a'.$v_read_size, $v_buffer); 3155 @fwrite($this->zip_fd, $v_buffer, $v_read_size); 3156 $v_size -= $v_read_size; 3157 } 3158 3159 // ----- Close the file 3160 @fclose($v_file_compressed); 3161 3162 // ----- Unlink the temporary file 3163 @unlink($v_gzip_temp_name); 3164 3165 // ----- Return 3166 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3167 return $v_result; 3167 3168 } 3168 3169 // -------------------------------------------------------------------------------- … … 3178 3179 function privCalculateStoredFilename(&$p_filedescr, &$p_options) 3179 3180 { 3180 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCalculateStoredFilename", "filename='".$p_filedescr['filename']."'");3181 $v_result=1;3182 3183 // ----- Working variables3184 $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 change3206 if (isset($p_filedescr['new_full_name'])) {3207 // ----- Remove drive letter if any3208 $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 change3213 else {3214 3215 // ----- Look for short name change3216 // Its when we cahnge just the filename but not the path3217 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 filename3228 $v_stored_filename = $p_filename;3229 }3230 3231 // ----- Look for all path to remove3232 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 remove3237 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 any3272 $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);3273 3274 // ----- Look for path to add3275 if ($p_add_dir != "") {3276 if (substr($p_add_dir, -1) == "/")3277 $v_stored_filename = $p_add_dir.$v_stored_filename;3278 else3279 $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 // ----- Return3290 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3291 return $v_result;3181 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCalculateStoredFilename", "filename='".$p_filedescr['filename']."'"); 3182 $v_result=1; 3183 3184 // ----- Working variables 3185 $p_filename = $p_filedescr['filename']; 3186 if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { 3187 $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; 3188 } 3189 else { 3190 $p_add_dir = ''; 3191 } 3192 if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { 3193 $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; 3194 } 3195 else { 3196 $p_remove_dir = ''; 3197 } 3198 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Remove path ='".$p_remove_dir."'"); 3199 if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { 3200 $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; 3201 } 3202 else { 3203 $p_remove_all_dir = 0; 3204 } 3205 3206 // ----- Look for full name change 3207 if (isset($p_filedescr['new_full_name'])) { 3208 // ----- Remove drive letter if any 3209 $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']); 3210 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing full name of '".$p_filename."' for '".$v_stored_filename."'"); 3211 } 3212 3213 // ----- Look for path and/or short name change 3214 else { 3215 3216 // ----- Look for short name change 3217 // Its when we cahnge just the filename but not the path 3218 if (isset($p_filedescr['new_short_name'])) { 3219 $v_path_info = pathinfo($p_filename); 3220 $v_dir = ''; 3221 if ($v_path_info['dirname'] != '') { 3222 $v_dir = $v_path_info['dirname'].'/'; 3223 } 3224 $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; 3225 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing short name of '".$p_filename."' for '".$v_stored_filename."'"); 3226 } 3227 else { 3228 // ----- Calculate the stored filename 3229 $v_stored_filename = $p_filename; 3230 } 3231 3232 // ----- Look for all path to remove 3233 if ($p_remove_all_dir) { 3234 $v_stored_filename = basename($p_filename); 3235 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove all path selected change '".$p_filename."' for '".$v_stored_filename."'"); 3236 } 3237 // ----- Look for partial path remove 3238 else if ($p_remove_dir != "") { 3239 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Partial path to remove"); 3240 if (substr($p_remove_dir, -1) != '/') 3241 $p_remove_dir .= "/"; 3242 3243 if ( (substr($p_filename, 0, 2) == "./") 3244 || (substr($p_remove_dir, 0, 2) == "./")) { 3245 3246 if ( (substr($p_filename, 0, 2) == "./") 3247 && (substr($p_remove_dir, 0, 2) != "./")) { 3248 $p_remove_dir = "./".$p_remove_dir; 3249 } 3250 if ( (substr($p_filename, 0, 2) != "./") 3251 && (substr($p_remove_dir, 0, 2) == "./")) { 3252 $p_remove_dir = substr($p_remove_dir, 2); 3253 } 3254 } 3255 3256 $v_compare = PclZipUtilPathInclusion($p_remove_dir, 3257 $v_stored_filename); 3258 if ($v_compare > 0) { 3259 if ($v_compare == 2) { 3260 $v_stored_filename = ""; 3261 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Path to remove is the current folder"); 3262 } 3263 else { 3264 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove path '$p_remove_dir' in file '$v_stored_filename'"); 3265 $v_stored_filename = substr($v_stored_filename, 3266 strlen($p_remove_dir)); 3267 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Result is '$v_stored_filename'"); 3268 } 3269 } 3270 } 3271 3272 // ----- Remove drive letter if any 3273 $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename); 3274 3275 // ----- Look for path to add 3276 if ($p_add_dir != "") { 3277 if (substr($p_add_dir, -1) == "/") 3278 $v_stored_filename = $p_add_dir.$v_stored_filename; 3279 else 3280 $v_stored_filename = $p_add_dir."/".$v_stored_filename; 3281 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_filename' = '$v_stored_filename'"); 3282 } 3283 } 3284 3285 // ----- Filename (reduce the path of stored name) 3286 $v_stored_filename = PclZipUtilPathReduction($v_stored_filename); 3287 $p_filedescr['stored_filename'] = $v_stored_filename; 3288 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Stored filename will be '".$p_filedescr['stored_filename']."', strlen ".strlen($p_filedescr['stored_filename'])); 3289 3290 // ----- Return 3291 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3292 return $v_result; 3292 3293 } 3293 3294 // -------------------------------------------------------------------------------- … … 3301 3302 function privWriteFileHeader(&$p_header) 3302 3303 { 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 file3307 $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/mtime3311 //--(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 data3317 $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'],3304 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"'); 3305 $v_result=1; 3306 3307 // ----- Store the offset position of the file 3308 $p_header['offset'] = ftell($this->zip_fd); 3309 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'File offset of the header :'.$p_header['offset']); 3310 3311 // ----- Transform UNIX mtime to DOS format mdate/mtime 3312 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 3313 $v_date = getdate($p_header['mtime']); 3314 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; 3315 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; 3316 3317 // ----- Packed data 3318 $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, 3319 $p_header['version_extracted'], $p_header['flag'], 3320 $p_header['compression'], $v_mtime, $v_mdate, 3321 $p_header['crc'], $p_header['compressed_size'], 3321 3322 $p_header['size'], 3322 strlen($p_header['stored_filename']),3323 strlen($p_header['stored_filename']), 3323 3324 $p_header['extra_len']); 3324 3325 3325 // ----- Write the first 148 bytes of the header in the archive3326 fputs($this->zip_fd, $v_binary_data, 30);3327 3328 // ----- Write the variable fields3329 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 // ----- Return3339 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3340 return $v_result;3326 // ----- Write the first 148 bytes of the header in the archive 3327 fputs($this->zip_fd, $v_binary_data, 30); 3328 3329 // ----- Write the variable fields 3330 if (strlen($p_header['stored_filename']) != 0) 3331 { 3332 fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); 3333 } 3334 if ($p_header['extra_len'] != 0) 3335 { 3336 fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); 3337 } 3338 3339 // ----- Return 3340 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3341 return $v_result; 3341 3342 } 3342 3343 // -------------------------------------------------------------------------------- … … 3350 3351 function privWriteCentralFileHeader(&$p_header) 3351 3352 { 3352 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"');3353 $v_result=1;3354 3355 // TBC3356 //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/mtime3361 //--(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 data3369 $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,3370 $p_header['version'], $p_header['version_extracted'],3371 $p_header['flag'], $p_header['compression'],3353 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"'); 3354 $v_result=1; 3355 3356 // TBC 3357 //for(reset($p_header); $key = key($p_header); next($p_header)) { 3358 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "header[$key] = ".$p_header[$key]); 3359 //} 3360 3361 // ----- Transform UNIX mtime to DOS format mdate/mtime 3362 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 3363 $v_date = getdate($p_header['mtime']); 3364 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; 3365 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; 3366 3367 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment size : \''.$p_header['comment_len'].'\''); 3368 3369 // ----- Packed data 3370 $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, 3371 $p_header['version'], $p_header['version_extracted'], 3372 $p_header['flag'], $p_header['compression'], 3372 3373 $v_mtime, $v_mdate, $p_header['crc'], 3373 $p_header['compressed_size'], $p_header['size'],3374 strlen($p_header['stored_filename']),3374 $p_header['compressed_size'], $p_header['size'], 3375 strlen($p_header['stored_filename']), 3375 3376 $p_header['extra_len'], $p_header['comment_len'], 3376 $p_header['disk'], $p_header['internal'],3377 $p_header['disk'], $p_header['internal'], 3377 3378 $p_header['external'], $p_header['offset']); 3378 3379 3379 // ----- Write the 42 bytes of the header in the zip file3380 fputs($this->zip_fd, $v_binary_data, 46);3381 3382 // ----- Write the variable fields3383 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 // ----- Return3397 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3398 return $v_result;3380 // ----- Write the 42 bytes of the header in the zip file 3381 fputs($this->zip_fd, $v_binary_data, 46); 3382 3383 // ----- Write the variable fields 3384 if (strlen($p_header['stored_filename']) != 0) 3385 { 3386 fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); 3387 } 3388 if ($p_header['extra_len'] != 0) 3389 { 3390 fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); 3391 } 3392 if ($p_header['comment_len'] != 0) 3393 { 3394 fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']); 3395 } 3396 3397 // ----- Return 3398 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3399 return $v_result; 3399 3400 } 3400 3401 // -------------------------------------------------------------------------------- … … 3408 3409 function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) 3409 3410 { 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 data3414 $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,3415 $p_nb_entries, $p_size,3411 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralHeader", 'nb_entries='.$p_nb_entries.', size='.$p_size.', offset='.$p_offset.', comment="'.$p_comment.'"'); 3412 $v_result=1; 3413 3414 // ----- Packed data 3415 $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, 3416 $p_nb_entries, $p_size, 3416 3417 $p_offset, strlen($p_comment)); 3417 3418 3418 // ----- Write the 22 bytes of the header in the zip file3419 fputs($this->zip_fd, $v_binary_data, 22);3420 3421 // ----- Write the variable fields3422 if (strlen($p_comment) != 0)3423 {3424 fputs($this->zip_fd, $p_comment, strlen($p_comment));3425 }3426 3427 // ----- Return3428 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3429 return $v_result;3419 // ----- Write the 22 bytes of the header in the zip file 3420 fputs($this->zip_fd, $v_binary_data, 22); 3421 3422 // ----- Write the variable fields 3423 if (strlen($p_comment) != 0) 3424 { 3425 fputs($this->zip_fd, $p_comment, strlen($p_comment)); 3426 } 3427 3428 // ----- Return 3429 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3430 return $v_result; 3430 3431 } 3431 3432 // -------------------------------------------------------------------------------- … … 3439 3440 function privList(&$p_list) 3440 3441 { 3441 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privList", "list");3442 $v_result=1;3443 3444 // ----- Magic quotes trick3445 $this->privDisableMagicQuotes();3446 3447 // ----- Open the zip file3448 //--(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 trick3452 $this->privSwapBackMagicQuotes();3453 3454 // ----- Error log3455 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');3456 3457 // ----- Return3458 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());3459 return PclZip::errorCode();3460 }3461 3462 // ----- Read the central directory informations3463 $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 Dir3472 //--(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 log3481 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');3482 3483 // ----- Return3484 //--(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 entry3490 for ($i=0; $i<$v_central_dir['entries']; $i++)3491 {3492 // ----- Read the file header3493 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 attributes3502 $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);3503 unset($v_header);3504 }3505 3506 // ----- Close the zip file3507 $this->privCloseFd();3508 3509 // ----- Magic quotes trick3510 $this->privSwapBackMagicQuotes();3511 3512 // ----- Return3513 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3514 return $v_result;3442 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privList", "list"); 3443 $v_result=1; 3444 3445 // ----- Magic quotes trick 3446 $this->privDisableMagicQuotes(); 3447 3448 // ----- Open the zip file 3449 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 3450 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) 3451 { 3452 // ----- Magic quotes trick 3453 $this->privSwapBackMagicQuotes(); 3454 3455 // ----- Error log 3456 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); 3457 3458 // ----- Return 3459 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3460 return PclZip::errorCode(); 3461 } 3462 3463 // ----- Read the central directory informations 3464 $v_central_dir = array(); 3465 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 3466 { 3467 $this->privSwapBackMagicQuotes(); 3468 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3469 return $v_result; 3470 } 3471 3472 // ----- Go to beginning of Central Dir 3473 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Offset : ".$v_central_dir['offset']."'"); 3474 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); 3475 @rewind($this->zip_fd); 3476 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); 3477 if (@fseek($this->zip_fd, $v_central_dir['offset'])) 3478 { 3479 $this->privSwapBackMagicQuotes(); 3480 3481 // ----- Error log 3482 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 3483 3484 // ----- Return 3485 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3486 return PclZip::errorCode(); 3487 } 3488 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); 3489 3490 // ----- Read each entry 3491 for ($i=0; $i<$v_central_dir['entries']; $i++) 3492 { 3493 // ----- Read the file header 3494 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) 3495 { 3496 $this->privSwapBackMagicQuotes(); 3497 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3498 return $v_result; 3499 } 3500 $v_header['index'] = $i; 3501 3502 // ----- Get the only interesting attributes 3503 $this->privConvertHeader2FileInfo($v_header, $p_list[$i]); 3504 unset($v_header); 3505 } 3506 3507 // ----- Close the zip file 3508 $this->privCloseFd(); 3509 3510 // ----- Magic quotes trick 3511 $this->privSwapBackMagicQuotes(); 3512 3513 // ----- Return 3514 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3515 return $v_result; 3515 3516 } 3516 3517 // -------------------------------------------------------------------------------- … … 3522 3523 // entries and extract the interesting parameters that will be given back. 3523 3524 // The resulting file infos are set in the array $p_info 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.3525 // $p_info['filename'] : Filename with full path. Given by user (add), 3526 // extracted in the filesystem (extract). 3527 // $p_info['stored_filename'] : Stored filename in the archive. 3528 // $p_info['size'] = Size of the file. 3529 // $p_info['compressed_size'] = Compressed size of the file. 3530 // $p_info['mtime'] = Last modification date of the file. 3531 // $p_info['comment'] = Comment associated with the file. 3532 // $p_info['folder'] = true/false : indicates if the entry is a folder or not. 3533 // $p_info['status'] = status of the action on the file. 3534 // $p_info['crc'] = CRC of the file content. 3534 3535 // Parameters : 3535 3536 // Return Values : … … 3537 3538 function privConvertHeader2FileInfo($p_header, &$p_info) 3538 3539 { 3539 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privConvertHeader2FileInfo", "Filename='".$p_header['filename']."'");3540 $v_result=1;3541 3542 // ----- Get the interesting attributes3543 $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 // ----- Return3555 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3556 return $v_result;3540 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privConvertHeader2FileInfo", "Filename='".$p_header['filename']."'"); 3541 $v_result=1; 3542 3543 // ----- Get the interesting attributes 3544 $p_info['filename'] = $p_header['filename']; 3545 $p_info['stored_filename'] = $p_header['stored_filename']; 3546 $p_info['size'] = $p_header['size']; 3547 $p_info['compressed_size'] = $p_header['compressed_size']; 3548 $p_info['mtime'] = $p_header['mtime']; 3549 $p_info['comment'] = $p_header['comment']; 3550 $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); 3551 $p_info['index'] = $p_header['index']; 3552 $p_info['status'] = $p_header['status']; 3553 $p_info['crc'] = $p_header['crc']; 3554 3555 // ----- Return 3556 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3557 return $v_result; 3557 3558 } 3558 3559 // -------------------------------------------------------------------------------- … … 3564 3565 // Parameters : 3565 3566 // $p_file_list : An array where will be placed the properties of each 3566 // extracted file3567 // extracted file 3567 3568 // $p_path : Path to add while writing the extracted files 3568 3569 // $p_remove_path : Path to remove (from the file memorized path) while writing the 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.3570 // extracted files. If the path does not match the file path, 3571 // the file is extracted with its memorized path. 3572 // $p_remove_path does not apply to 'list' mode. 3573 // $p_path and $p_remove_path are commulative. 3573 3574 // Return Values : 3574 3575 // 1 on success,0 or less on error (see error code list) … … 3576 3577 function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) 3577 3578 { 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 trick3582 $this->privDisableMagicQuotes();3583 3584 // ----- Check the path3585 if ( ($p_path == "")3586 || ( (substr($p_path, 0, 1) != "/")3587 && (substr($p_path, 0, 3) != "../")3579 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privExtractByRule", "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'"); 3580 $v_result=1; 3581 3582 // ----- Magic quotes trick 3583 $this->privDisableMagicQuotes(); 3584 3585 // ----- Check the path 3586 if ( ($p_path == "") 3587 || ( (substr($p_path, 0, 1) != "/") 3588 && (substr($p_path, 0, 3) != "../") 3588 3589 && (substr($p_path,1,2)!=":/"))) 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 file3611 //--(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 informations3620 $v_central_dir = array();3621 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)3622 {3623 // ----- Close the zip file3624 $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 Dir3632 $v_pos_entry = $v_central_dir['offset'];3633 3634 // ----- Read each entry3635 $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 entry3641 //--(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 file3647 $this->privCloseFd();3648 $this->privSwapBackMagicQuotes();3649 3650 // ----- Error log3651 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');3652 3653 // ----- Return3654 //--(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 header3660 $v_header = array();3661 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)3662 {3663 // ----- Close the zip file3664 $this->privCloseFd();3665 $this->privSwapBackMagicQuotes();3666 3667 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3668 return $v_result;3669 }3670 3671 // ----- Store the index3672 $v_header['index'] = $i;3673 3674 // ----- Store the file position3675 $v_pos_entry = ftell($this->zip_fd);3676 3677 // ----- Look for the specific extract rules3678 $v_extract = false;3679 3680 // ----- Look for extract by name rule3681 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 list3686 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 directory3690 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 path3694 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 filename3701 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 rule3709 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 rule3720 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 rule3731 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 list3736 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 archive3756 else {3757 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with no rule (extract all)");3758 $v_extract = true;3759 }3590 $p_path = "./".$p_path; 3591 3592 // ----- Reduce the path last (and duplicated) '/' 3593 if (($p_path != "./") && ($p_path != "/")) 3594 { 3595 // ----- Look for the path end '/' 3596 while (substr($p_path, -1) == "/") 3597 { 3598 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'"); 3599 $p_path = substr($p_path, 0, strlen($p_path)-1); 3600 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]"); 3601 } 3602 } 3603 3604 // ----- Look for path to remove format (should end by /) 3605 if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/')) 3606 { 3607 $p_remove_path .= '/'; 3608 } 3609 $p_remove_path_size = strlen($p_remove_path); 3610 3611 // ----- Open the zip file 3612 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 3613 if (($v_result = $this->privOpenFd('rb')) != 1) 3614 { 3615 $this->privSwapBackMagicQuotes(); 3616 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3617 return $v_result; 3618 } 3619 3620 // ----- Read the central directory informations 3621 $v_central_dir = array(); 3622 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 3623 { 3624 // ----- Close the zip file 3625 $this->privCloseFd(); 3626 $this->privSwapBackMagicQuotes(); 3627 3628 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3629 return $v_result; 3630 } 3631 3632 // ----- Start at beginning of Central Dir 3633 $v_pos_entry = $v_central_dir['offset']; 3634 3635 // ----- Read each entry 3636 $j_start = 0; 3637 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) 3638 { 3639 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry : '$i'"); 3640 3641 // ----- Read next Central dir entry 3642 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position before rewind : ".ftell($this->zip_fd)."'"); 3643 @rewind($this->zip_fd); 3644 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position after rewind : ".ftell($this->zip_fd)."'"); 3645 if (@fseek($this->zip_fd, $v_pos_entry)) 3646 { 3647 // ----- Close the zip file 3648 $this->privCloseFd(); 3649 $this->privSwapBackMagicQuotes(); 3650 3651 // ----- Error log 3652 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 3653 3654 // ----- Return 3655 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3656 return PclZip::errorCode(); 3657 } 3658 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position after fseek : ".ftell($this->zip_fd)."'"); 3659 3660 // ----- Read the file header 3661 $v_header = array(); 3662 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) 3663 { 3664 // ----- Close the zip file 3665 $this->privCloseFd(); 3666 $this->privSwapBackMagicQuotes(); 3667 3668 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3669 return $v_result; 3670 } 3671 3672 // ----- Store the index 3673 $v_header['index'] = $i; 3674 3675 // ----- Store the file position 3676 $v_pos_entry = ftell($this->zip_fd); 3677 3678 // ----- Look for the specific extract rules 3679 $v_extract = false; 3680 3681 // ----- Look for extract by name rule 3682 if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) 3683 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { 3684 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'"); 3685 3686 // ----- Look if the filename is in the list 3687 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { 3688 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'"); 3689 3690 // ----- Look for a directory 3691 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { 3692 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory"); 3693 3694 // ----- Look if the directory is in the filename path 3695 if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) 3696 && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { 3697 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path"); 3698 $v_extract = true; 3699 } 3700 } 3701 // ----- Look for a filename 3702 elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { 3703 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one."); 3704 $v_extract = true; 3705 } 3706 } 3707 } 3708 3709 // ----- Look for extract by ereg rule 3710 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) 3711 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { 3712 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'"); 3713 3714 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) { 3715 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); 3716 $v_extract = true; 3717 } 3718 } 3719 3720 // ----- Look for extract by preg rule 3721 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) 3722 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { 3723 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'"); 3724 3725 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { 3726 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); 3727 $v_extract = true; 3728 } 3729 } 3730 3731 // ----- Look for extract by index rule 3732 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) 3733 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { 3734 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'"); 3735 3736 // ----- Look if the index is in the list 3737 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { 3738 //--(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']."]"); 3739 3740 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { 3741 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range"); 3742 $v_extract = true; 3743 } 3744 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { 3745 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop"); 3746 $j_start = $j+1; 3747 } 3748 3749 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { 3750 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop"); 3751 break; 3752 } 3753 } 3754 } 3755 3756 // ----- Look for no rule, which means extract all the archive 3757 else { 3758 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with no rule (extract all)"); 3759 $v_extract = true; 3760 } 3760 3761 3761 3762 // ----- Check compression method 3762 3763 if ( ($v_extract) 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_ERROR3769 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();3764 && ( ($v_header['compression'] != 8) 3765 && ($v_header['compression'] != 0))) { 3766 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported compression method (".$v_header['compression'].")"); 3767 $v_header['status'] = 'unsupported_compression'; 3768 3769 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 3770 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 3771 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 3772 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 3773 3774 $this->privSwapBackMagicQuotes(); 3775 3776 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, 3777 "Filename '".$v_header['stored_filename']."' is " 3778 ."compressed by an unsupported compression " 3779 ."method (".$v_header['compression'].") "); 3780 3781 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3782 return PclZip::errorCode(); 3782 3783 } 3783 3784 } … … 3785 3786 // ----- Check encrypted files 3786 3787 if (($v_extract) && (($v_header['flag'] & 1) == 1)) { 3787 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported file encryption");3788 $v_header['status'] = 'unsupported_encryption';3789 3790 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR3791 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']3788 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported file encryption"); 3789 $v_header['status'] = 'unsupported_encryption'; 3790 3791 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 3792 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 3793 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 3794 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 3795 3796 $this->privSwapBackMagicQuotes(); 3797 3798 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 3799 "Unsupported encryption for " 3800 ." filename '".$v_header['stored_filename'] 3800 3801 ."'"); 3801 3802 3802 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());3803 return PclZip::errorCode();3803 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3804 return PclZip::errorCode(); 3804 3805 } 3805 }3806 3807 // ----- Look for real extraction3808 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 extraction3823 if ($v_extract)3824 {3825 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file '".$v_header['filename']."', index '$i'");3826 3827 // ----- Go to the file position3828 //--(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 file3834 $this->privCloseFd();3835 3836 $this->privSwapBackMagicQuotes();3837 3838 // ----- Error log3839 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');3840 3841 // ----- Return3842 //--(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 string3848 if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {3849 3850 // ----- Extracting the file3851 $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 attributes3860 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)3861 {3862 // ----- Close the zip file3863 $this->privCloseFd();3864 $this->privSwapBackMagicQuotes();3865 3866 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3867 return $v_result;3868 }3869 3870 // ----- Set the file content3871 $p_file_list[$v_nb_extracted]['content'] = $v_string;3872 3873 // ----- Next extracted file3874 $v_nb_extracted++;3875 3876 // ----- Look for user callback abort3877 if ($v_result1 == 2) {3878 break;3879 }3880 }3881 // ----- Look for extraction in standard output3882 elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))3883 && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {3884 // ----- Extracting the file in standard output3885 $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 attributes3894 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 abort3902 if ($v_result1 == 2) {3903 break;3904 }3905 }3906 // ----- Look for normal extraction3907 else {3908 // ----- Extracting the file3909 $v_result1 = $this->privExtractFile($v_header,3910 $p_path, $p_remove_path,3806 } 3807 3808 // ----- Look for real extraction 3809 if (($v_extract) && ($v_header['status'] != 'ok')) { 3810 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "No need for extract"); 3811 $v_result = $this->privConvertHeader2FileInfo($v_header, 3812 $p_file_list[$v_nb_extracted++]); 3813 if ($v_result != 1) { 3814 $this->privCloseFd(); 3815 $this->privSwapBackMagicQuotes(); 3816 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3817 return $v_result; 3818 } 3819 3820 $v_extract = false; 3821 } 3822 3823 // ----- Look for real extraction 3824 if ($v_extract) 3825 { 3826 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file '".$v_header['filename']."', index '$i'"); 3827 3828 // ----- Go to the file position 3829 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); 3830 @rewind($this->zip_fd); 3831 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); 3832 if (@fseek($this->zip_fd, $v_header['offset'])) 3833 { 3834 // ----- Close the zip file 3835 $this->privCloseFd(); 3836 3837 $this->privSwapBackMagicQuotes(); 3838 3839 // ----- Error log 3840 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 3841 3842 // ----- Return 3843 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3844 return PclZip::errorCode(); 3845 } 3846 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); 3847 3848 // ----- Look for extraction as string 3849 if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) { 3850 3851 // ----- Extracting the file 3852 $v_result1 = $this->privExtractFileAsString($v_header, $v_string); 3853 if ($v_result1 < 1) { 3854 $this->privCloseFd(); 3855 $this->privSwapBackMagicQuotes(); 3856 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1); 3857 return $v_result1; 3858 } 3859 3860 // ----- Get the only interesting attributes 3861 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) 3862 { 3863 // ----- Close the zip file 3864 $this->privCloseFd(); 3865 $this->privSwapBackMagicQuotes(); 3866 3867 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3868 return $v_result; 3869 } 3870 3871 // ----- Set the file content 3872 $p_file_list[$v_nb_extracted]['content'] = $v_string; 3873 3874 // ----- Next extracted file 3875 $v_nb_extracted++; 3876 3877 // ----- Look for user callback abort 3878 if ($v_result1 == 2) { 3879 break; 3880 } 3881 } 3882 // ----- Look for extraction in standard output 3883 elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) 3884 && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { 3885 // ----- Extracting the file in standard output 3886 $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); 3887 if ($v_result1 < 1) { 3888 $this->privCloseFd(); 3889 $this->privSwapBackMagicQuotes(); 3890 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1); 3891 return $v_result1; 3892 } 3893 3894 // ----- Get the only interesting attributes 3895 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { 3896 $this->privCloseFd(); 3897 $this->privSwapBackMagicQuotes(); 3898 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3899 return $v_result; 3900 } 3901 3902 // ----- Look for user callback abort 3903 if ($v_result1 == 2) { 3904 break; 3905 } 3906 } 3907 // ----- Look for normal extraction 3908 else { 3909 // ----- Extracting the file 3910 $v_result1 = $this->privExtractFile($v_header, 3911 $p_path, $p_remove_path, 3911 3912 $p_remove_all_path, 3912 3913 $p_options); 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 attributes3921 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)3922 {3923 // ----- Close the zip file3924 $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 abort3932 if ($v_result1 == 2) {3933 break;3934 }3935 }3936 }3937 }3938 3939 // ----- Close the zip file3940 $this->privCloseFd();3941 $this->privSwapBackMagicQuotes();3942 3943 // ----- Return3944 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);3945 return $v_result;3914 if ($v_result1 < 1) { 3915 $this->privCloseFd(); 3916 $this->privSwapBackMagicQuotes(); 3917 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1); 3918 return $v_result1; 3919 } 3920 3921 // ----- Get the only interesting attributes 3922 if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) 3923 { 3924 // ----- Close the zip file 3925 $this->privCloseFd(); 3926 $this->privSwapBackMagicQuotes(); 3927 3928 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3929 return $v_result; 3930 } 3931 3932 // ----- Look for user callback abort 3933 if ($v_result1 == 2) { 3934 break; 3935 } 3936 } 3937 } 3938 } 3939 3940 // ----- Close the zip file 3941 $this->privCloseFd(); 3942 $this->privSwapBackMagicQuotes(); 3943 3944 // ----- Return 3945 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3946 return $v_result; 3946 3947 } 3947 3948 // -------------------------------------------------------------------------------- … … 3958 3959 function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) 3959 3960 { 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']; 3961 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'"); 3962 $v_result=1; 3963 3964 // ----- Read the file header 3965 if (($v_result = $this->privReadFileHeader($v_header)) != 1) 3966 { 3967 // ----- Return 3968 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3969 return $v_result; 3970 } 3971 3972 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); 3973 3974 // ----- Check that the file header is coherent with $p_entry info 3975 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { 3976 // TBC 3977 } 3978 3979 // ----- Look for all path to remove 3980 if ($p_remove_all_path == true) { 3981 // ----- Look for folder entry that not need to be extracted 3982 if (($p_entry['external']&0x00000010)==0x00000010) { 3983 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The entry is a folder : need to be filtered"); 3984 3985 $p_entry['status'] = "filtered"; 3986 3987 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3988 return $v_result; 3989 } 3990 3991 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "All path is removed"); 3992 // ----- Get the basename of the path 3993 $p_entry['filename'] = basename($p_entry['filename']); 3994 } 3995 3996 // ----- Look for path to remove 3997 else if ($p_remove_path != "") 3998 { 3999 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look for some path to remove"); 4000 if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) 4001 { 4002 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '".$p_entry['filename']."'"); 4003 4004 // ----- Change the file status 4005 $p_entry['status'] = "filtered"; 4006 4007 // ----- Return 4008 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4009 return $v_result; 4010 } 4011 4012 $p_remove_path_size = strlen($p_remove_path); 4013 if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) 4014 { 4015 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '".$p_entry['filename']."'"); 4016 4017 // ----- Remove the path 4018 $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); 4019 4020 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '".$p_entry['filename']."'"); 4021 } 4022 } 4023 4024 // ----- Add the path 4025 if ($p_path != '') { 4026 $p_entry['filename'] = $p_path."/".$p_entry['filename']; 4027 } 4028 4029 // ----- Check a base_dir_restriction 4030 if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { 4031 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Check the extract directory restriction"); 4032 $v_inclusion 4033 = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], 4034 $p_entry['filename']); 4035 if ($v_inclusion == 0) { 4036 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction"); 4037 4038 PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, 4039 "Filename '".$p_entry['filename']."' is " 4040 ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); 4041 4042 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4043 return PclZip::errorCode(); 4044 } 4045 } 4046 4047 // ----- Look for pre-extract callback 4048 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { 4049 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction"); 4050 4051 // ----- Generate a local information 4052 $v_local_header = array(); 4053 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 4054 4055 // ----- Call the callback 4056 // Here I do not use call_user_func() because I need to send a reference to the 4057 // header. 4058 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); 4059 if ($v_result == 0) { 4060 // ----- Change the file status 4061 $p_entry['status'] = "skipped"; 4062 $v_result = 1; 4063 } 4064 4065 // ----- Look for abort result 4066 if ($v_result == 2) { 4067 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); 4068 // ----- This status is internal and will be changed in 'skipped' 4069 $p_entry['status'] = "aborted"; 4070 $v_result = PCLZIP_ERR_USER_ABORTED; 4071 } 4072 4073 // ----- Update the informations 4074 // Only some fields can be modified 4075 $p_entry['filename'] = $v_local_header['filename']; 4076 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'"); 4077 } 4078 4079 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'"); 4080 4081 // ----- Look if extraction should be done 4082 if ($p_entry['status'] == 'ok') { 4083 4084 // ----- Look for specific actions while the file exist 4085 if (file_exists($p_entry['filename'])) 4086 { 4087 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_entry['filename']."' already exists"); 4088 4089 // ----- Look if file is a directory 4090 if (is_dir($p_entry['filename'])) 4091 { 4092 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is a directory"); 4093 4094 // ----- Change the file status 4095 $p_entry['status'] = "already_a_directory"; 4096 4097 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 4098 // For historical reason first PclZip implementation does not stop 4099 // when this kind of error occurs. 4100 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 4101 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 4102 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 4103 4104 PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, 4105 "Filename '".$p_entry['filename']."' is " 4106 ."already used by an existing directory"); 4107 4108 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4109 return PclZip::errorCode(); 4110 } 4111 } 4112 // ----- Look if file is write protected 4113 else if (!is_writeable($p_entry['filename'])) 4114 { 4115 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is write protected"); 4116 4117 // ----- Change the file status 4118 $p_entry['status'] = "write_protected"; 4119 4120 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 4121 // For historical reason first PclZip implementation does not stop 4122 // when this kind of error occurs. 4123 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 4124 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 4125 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 4126 4127 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 4128 "Filename '".$p_entry['filename']."' exists " 4129 ."and is write protected"); 4130 4131 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4132 return PclZip::errorCode(); 4133 } 4134 } 4135 4136 // ----- Look if the extracted file is older 4137 else if (filemtime($p_entry['filename']) > $p_entry['mtime']) 4138 { 4139 //--(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']).")"); 4140 // ----- Change the file status 4141 if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) 4142 && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { 4143 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_REPLACE_NEWER is selected, file will be replaced"); 4144 } 4145 else { 4146 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be replaced"); 4147 $p_entry['status'] = "newer_exist"; 4148 4149 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 4150 // For historical reason first PclZip implementation does not stop 4151 // when this kind of error occurs. 4152 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) 4153 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { 4154 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 4155 4156 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 4157 "Newer version of '".$p_entry['filename']."' exists " 4158 ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); 4159 4160 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4161 return PclZip::errorCode(); 4162 } 4163 } 4164 } 4165 else { 4166 //--(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']).")"); 4167 } 4168 } 4169 4170 // ----- Check the directory availability and create it if necessary 4171 else { 4172 if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) 4173 $v_dir_to_check = $p_entry['filename']; 4174 else if (!strstr($p_entry['filename'], "/")) 4175 $v_dir_to_check = ""; 4176 else 4177 $v_dir_to_check = dirname($p_entry['filename']); 4178 4179 if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { 4180 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '".$p_entry['filename']."'"); 4181 4182 // ----- Change the file status 4183 $p_entry['status'] = "path_creation_fail"; 4184 4185 // ----- Return 4186 ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4187 //return $v_result; 4188 $v_result = 1; 4189 } 4190 } 4191 } 4192 4193 // ----- Look if extraction should be done 4194 if ($p_entry['status'] == 'ok') { 4195 4196 // ----- Do the extraction (if not a folder) 4197 if (!(($p_entry['external']&0x00000010)==0x00000010)) 4198 { 4199 // ----- Look for not compressed file 4200 if ($p_entry['compression'] == 0) { 4201 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); 4202 4203 // ----- Opening destination file 4204 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) 4205 { 4206 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); 4207 4208 // ----- Change the file status 4209 $p_entry['status'] = "write_error"; 4210 4211 // ----- Return 4212 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4213 return $v_result; 4214 } 4215 4216 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read '".$p_entry['size']."' bytes"); 4217 4218 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks 4219 $v_size = $p_entry['compressed_size']; 4220 while ($v_size != 0) 4221 { 4222 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 4223 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes"); 4224 $v_buffer = @fread($this->zip_fd, $v_read_size); 4225 /* Try to speed up the code 4226 $v_binary_data = pack('a'.$v_read_size, $v_buffer); 4227 @fwrite($v_dest_file, $v_binary_data, $v_read_size); 4228 */ 4229 @fwrite($v_dest_file, $v_buffer, $v_read_size); 4230 $v_size -= $v_read_size; 4231 } 4232 4233 // ----- Closing the destination file 4234 fclose($v_dest_file); 4235 4236 // ----- Change the file mtime 4237 touch($p_entry['filename'], $p_entry['mtime']); 4238 4239 4240 } 4241 else { 4242 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (Compression method ".$p_entry['compression'].")"); 4243 // ----- TBC 4244 // Need to be finished 4245 if (($p_entry['flag'] & 1) == 1) { 4246 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File is encrypted"); 4247 /* 4248 // ----- Read the encryption header 4249 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read 12 encryption header bytes"); 4250 $v_encryption_header = @fread($this->zip_fd, 12); 4251 4252 // ----- Read the encrypted & compressed file in a buffer 4253 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".($p_entry['compressed_size']-12)."' compressed & encrypted bytes"); 4254 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']-12); 4255 4256 // ----- Decrypt the buffer 4257 $this->privDecrypt($v_encryption_header, $v_buffer, 4258 $p_entry['compressed_size']-12, $p_entry['crc']); 4259 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Buffer is '".$v_buffer."'"); 4260 */ 4261 } 4262 else { 4263 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".$p_entry['compressed_size']."' compressed bytes"); 4264 // ----- Read the compressed file in a buffer (one shot) 4265 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 4266 } 4267 4268 // ----- Decompress the file 4269 $v_file_content = @gzinflate($v_buffer); 4270 unset($v_buffer); 4271 if ($v_file_content === FALSE) { 4272 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to inflate compressed file"); 4273 4274 // ----- Change the file status 4275 // TBC 4276 $p_entry['status'] = "error"; 4277 4278 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4279 return $v_result; 4280 } 4281 4282 // ----- Opening destination file 4283 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { 4284 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); 4285 4286 // ----- Change the file status 4287 $p_entry['status'] = "write_error"; 4288 4289 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4290 return $v_result; 4291 } 4292 4293 // ----- Write the uncompressed data 4294 @fwrite($v_dest_file, $v_file_content, $p_entry['size']); 4295 unset($v_file_content); 4296 4297 // ----- Closing the destination file 4298 @fclose($v_dest_file); 4299 4300 // ----- Change the file mtime 4301 @touch($p_entry['filename'], $p_entry['mtime']); 4302 } 4303 4304 // ----- Look for chmod option 4305 if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { 4306 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "chmod option activated '".$p_options[PCLZIP_OPT_SET_CHMOD]."'"); 4307 4308 // ----- Change the mode of the file 4309 @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); 4310 } 4311 4312 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); 4313 } 4314 } 4315 4316 // ----- Change abort status 4317 if ($p_entry['status'] == "aborted") { 4318 $p_entry['status'] = "skipped"; 4026 4319 } 4027 4320 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 " 4039 ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); 4040 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 " 4105 ."already used by an existing directory"); 4106 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 " 4128 ."and is write protected"); 4129 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 4239 } 4240 else { 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 4281 // ----- Opening destination file 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 } 4314 4315 // ----- Change abort status 4316 if ($p_entry['status'] == "aborted") { 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; 4321 // ----- Look for post-extract callback 4322 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { 4323 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction"); 4324 4325 // ----- Generate a local information 4326 $v_local_header = array(); 4327 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 4328 4329 // ----- Call the callback 4330 // Here I do not use call_user_func() because I need to send a reference to the 4331 // header. 4332 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); 4333 4334 // ----- Look for abort result 4335 if ($v_result == 2) { 4336 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); 4337 $v_result = PCLZIP_ERR_USER_ABORTED; 4338 } 4339 } 4340 4341 // ----- Return 4342 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4343 return $v_result; 4343 4344 } 4344 4345 // -------------------------------------------------------------------------------- … … 4352 4353 function privExtractFileInOutput(&$p_entry, &$p_options) 4353 4354 { 4354 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileInOutput', "");4355 $v_result=1;4356 4357 // ----- Read the file header4358 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 info4366 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {4367 // TBC4368 }4369 4370 // ----- Look for pre-extract callback4371 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 information4375 $v_local_header = array();4376 $this->privConvertHeader2FileInfo($p_entry, $v_local_header);4377 4378 // ----- Call the callback4379 // Here I do not use call_user_func() because I need to send a reference to the4380 // 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 status4384 $p_entry['status'] = "skipped";4385 $v_result = 1;4386 }4387 4388 // ----- Look for abort result4389 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 informations4397 // Only some fields can be modified4398 $p_entry['filename'] = $v_local_header['filename'];4399 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");4400 }4401 4402 // ----- Trace4403 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");4404 4405 // ----- Look if extraction should be done4406 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 file4411 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 output4419 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 file4430 $v_file_content = gzinflate($v_buffer);4431 unset($v_buffer);4432 4433 // ----- Send the file to the output4434 echo $v_file_content;4435 unset($v_file_content);4436 }4437 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");4438 }4439 }4355 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileInOutput', ""); 4356 $v_result=1; 4357 4358 // ----- Read the file header 4359 if (($v_result = $this->privReadFileHeader($v_header)) != 1) { 4360 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4361 return $v_result; 4362 } 4363 4364 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); 4365 4366 // ----- Check that the file header is coherent with $p_entry info 4367 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { 4368 // TBC 4369 } 4370 4371 // ----- Look for pre-extract callback 4372 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { 4373 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction"); 4374 4375 // ----- Generate a local information 4376 $v_local_header = array(); 4377 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 4378 4379 // ----- Call the callback 4380 // Here I do not use call_user_func() because I need to send a reference to the 4381 // header. 4382 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); 4383 if ($v_result == 0) { 4384 // ----- Change the file status 4385 $p_entry['status'] = "skipped"; 4386 $v_result = 1; 4387 } 4388 4389 // ----- Look for abort result 4390 if ($v_result == 2) { 4391 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); 4392 // ----- This status is internal and will be changed in 'skipped' 4393 $p_entry['status'] = "aborted"; 4394 $v_result = PCLZIP_ERR_USER_ABORTED; 4395 } 4396 4397 // ----- Update the informations 4398 // Only some fields can be modified 4399 $p_entry['filename'] = $v_local_header['filename']; 4400 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'"); 4401 } 4402 4403 // ----- Trace 4404 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'"); 4405 4406 // ----- Look if extraction should be done 4407 if ($p_entry['status'] == 'ok') { 4408 4409 // ----- Do the extraction (if not a folder) 4410 if (!(($p_entry['external']&0x00000010)==0x00000010)) { 4411 // ----- Look for not compressed file 4412 if ($p_entry['compressed_size'] == $p_entry['size']) { 4413 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); 4414 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes"); 4415 4416 // ----- Read the file in a buffer (one shot) 4417 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 4418 4419 // ----- Send the file to the output 4420 echo $v_buffer; 4421 unset($v_buffer); 4422 } 4423 else { 4424 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file"); 4425 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Reading '".$p_entry['size']."' bytes"); 4426 4427 // ----- Read the compressed file in a buffer (one shot) 4428 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 4429 4430 // ----- Decompress the file 4431 $v_file_content = gzinflate($v_buffer); 4432 unset($v_buffer); 4433 4434 // ----- Send the file to the output 4435 echo $v_file_content; 4436 unset($v_file_content); 4437 } 4438 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); 4439 } 4440 } 4440 4441 4441 4442 // ----- Change abort status 4442 4443 if ($p_entry['status'] == "aborted") { 4443 $p_entry['status'] = "skipped";4444 $p_entry['status'] = "skipped"; 4444 4445 } 4445 4446 4446 // ----- Look for post-extract callback4447 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 information4451 $v_local_header = array();4452 $this->privConvertHeader2FileInfo($p_entry, $v_local_header);4453 4454 // ----- Call the callback4455 // Here I do not use call_user_func() because I need to send a reference to the4456 // header.4457 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');4458 4459 // ----- Look for abort result4460 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;4447 // ----- Look for post-extract callback 4448 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { 4449 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction"); 4450 4451 // ----- Generate a local information 4452 $v_local_header = array(); 4453 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); 4454 4455 // ----- Call the callback 4456 // Here I do not use call_user_func() because I need to send a reference to the 4457 // header. 4458 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); 4459 4460 // ----- Look for abort result 4461 if ($v_result == 2) { 4462 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); 4463 $v_result = PCLZIP_ERR_USER_ABORTED; 4464 } 4465 } 4466 4467 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4468 return $v_result; 4468 4469 } 4469 4470 // -------------------------------------------------------------------------------- … … 4477 4478 function privExtractFileAsString(&$p_entry, &$p_string) 4478 4479 { 4479 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileAsString', "p_entry['filename']='".$p_entry['filename']."'");4480 $v_result=1;4481 4482 // ----- Read the file header4483 $v_header = array();4484 if (($v_result = $this->privReadFileHeader($v_header)) != 1)4485 {4486 // ----- Return4487 //--(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 info4494 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {4495 // TBC4496 }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 file4504 // 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 file4510 $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 file4516 $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);4517 4518 // ----- Decompress the file4519 if (($p_string = @gzinflate($v_data)) === FALSE) {4520 // TBC4521 }4522 }4523 4524 // ----- Trace4525 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");4526 }4527 else {4528 // TBC : error : can not extract a folder in a string4529 }4530 4531 // ----- Return4532 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4533 return $v_result;4480 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileAsString', "p_entry['filename']='".$p_entry['filename']."'"); 4481 $v_result=1; 4482 4483 // ----- Read the file header 4484 $v_header = array(); 4485 if (($v_result = $this->privReadFileHeader($v_header)) != 1) 4486 { 4487 // ----- Return 4488 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4489 return $v_result; 4490 } 4491 4492 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); 4493 4494 // ----- Check that the file header is coherent with $p_entry info 4495 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { 4496 // TBC 4497 } 4498 4499 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file in string (with path) '".$p_entry['filename']."', size '$v_header[size]'"); 4500 4501 // ----- Do the extraction (if not a folder) 4502 if (!(($p_entry['external']&0x00000010)==0x00000010)) 4503 { 4504 // ----- Look for not compressed file 4505 // if ($p_entry['compressed_size'] == $p_entry['size']) 4506 if ($p_entry['compression'] == 0) { 4507 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); 4508 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes"); 4509 4510 // ----- Reading the file 4511 $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); 4512 } 4513 else { 4514 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (compression method '".$p_entry['compression']."')"); 4515 4516 // ----- Reading the file 4517 $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); 4518 4519 // ----- Decompress the file 4520 if (($p_string = @gzinflate($v_data)) === FALSE) { 4521 // TBC 4522 } 4523 } 4524 4525 // ----- Trace 4526 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); 4527 } 4528 else { 4529 // TBC : error : can not extract a folder in a string 4530 } 4531 4532 // ----- Return 4533 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4534 return $v_result; 4534 4535 } 4535 4536 // -------------------------------------------------------------------------------- … … 4543 4544 function privReadFileHeader(&$p_header) 4544 4545 { 4545 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadFileHeader", "");4546 $v_result=1;4547 4548 // ----- Read the 4 bytes signature4549 $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 signature4555 if ($v_data['id'] != 0x04034b50)4556 {4557 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid File header");4558 4559 // ----- Error log4560 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');4561 4562 // ----- Return4563 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());4564 return PclZip::errorCode();4565 }4566 4567 // ----- Read the first 42 bytes of the header4568 $v_binary_data = fread($this->zip_fd, 26);4569 4570 // ----- Look for invalid block size4571 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 log4578 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));4579 4580 // ----- Return4581 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());4582 return PclZip::errorCode();4583 }4584 4585 // ----- Extract the values4586 //--(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 filename4591 //--(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_fields4596 //--(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 properties4606 $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 format4624 $p_header['mdate'] = $v_data['mdate'];4625 $p_header['mtime'] = $v_data['mtime'];4626 if ($p_header['mdate'] && $p_header['mtime'])4627 {4628 // ----- Extract time4629 $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 date4634 $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 format4639 $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 else4644 {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 // TBC4650 //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 filename4655 $p_header['stored_filename'] = $p_header['filename'];4656 4657 // ----- Set the status field4658 $p_header['status'] = "ok";4659 4660 // ----- Return4661 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4662 return $v_result;4546 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadFileHeader", ""); 4547 $v_result=1; 4548 4549 // ----- Read the 4 bytes signature 4550 $v_binary_data = @fread($this->zip_fd, 4); 4551 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); 4552 $v_data = unpack('Vid', $v_binary_data); 4553 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); 4554 4555 // ----- Check signature 4556 if ($v_data['id'] != 0x04034b50) 4557 { 4558 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid File header"); 4559 4560 // ----- Error log 4561 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); 4562 4563 // ----- Return 4564 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4565 return PclZip::errorCode(); 4566 } 4567 4568 // ----- Read the first 42 bytes of the header 4569 $v_binary_data = fread($this->zip_fd, 26); 4570 4571 // ----- Look for invalid block size 4572 if (strlen($v_binary_data) != 26) 4573 { 4574 $p_header['filename'] = ""; 4575 $p_header['status'] = "invalid_header"; 4576 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data)); 4577 4578 // ----- Error log 4579 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); 4580 4581 // ----- Return 4582 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4583 return PclZip::errorCode(); 4584 } 4585 4586 // ----- Extract the values 4587 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header : '".$v_binary_data."'"); 4588 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header (Hex) : '".bin2hex($v_binary_data)."'"); 4589 $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); 4590 4591 // ----- Get filename 4592 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "File name length : ".$v_data['filename_len']); 4593 $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); 4594 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename : \''.$p_header['filename'].'\''); 4595 4596 // ----- Get extra_fields 4597 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extra field length : ".$v_data['extra_len']); 4598 if ($v_data['extra_len'] != 0) { 4599 $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); 4600 } 4601 else { 4602 $p_header['extra'] = ''; 4603 } 4604 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Extra field : \''.bin2hex($p_header['extra']).'\''); 4605 4606 // ----- Extract properties 4607 $p_header['version_extracted'] = $v_data['version']; 4608 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : ('.$p_header['version_extracted'].') \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\''); 4609 $p_header['compression'] = $v_data['compression']; 4610 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compression method : \''.$p_header['compression'].'\''); 4611 $p_header['size'] = $v_data['size']; 4612 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_header['size'].'\''); 4613 $p_header['compressed_size'] = $v_data['compressed_size']; 4614 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_header['compressed_size'].'\''); 4615 $p_header['crc'] = $v_data['crc']; 4616 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); 4617 $p_header['flag'] = $v_data['flag']; 4618 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag : \''.$p_header['flag'].'\''); 4619 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag bit 11 (from right) : \''.($p_header['flag']&0x0400).'\''); 4620 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag bit 11 (from left) : \''.($p_header['flag']&0x0020).'\''); 4621 $p_header['filename_len'] = $v_data['filename_len']; 4622 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename_len : \''.$p_header['filename_len'].'\''); 4623 4624 // ----- Recuperate date in UNIX format 4625 $p_header['mdate'] = $v_data['mdate']; 4626 $p_header['mtime'] = $v_data['mtime']; 4627 if ($p_header['mdate'] && $p_header['mtime']) 4628 { 4629 // ----- Extract time 4630 $v_hour = ($p_header['mtime'] & 0xF800) >> 11; 4631 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; 4632 $v_seconde = ($p_header['mtime'] & 0x001F)*2; 4633 4634 // ----- Extract date 4635 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; 4636 $v_month = ($p_header['mdate'] & 0x01E0) >> 5; 4637 $v_day = $p_header['mdate'] & 0x001F; 4638 4639 // ----- Get UNIX date format 4640 $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 4641 4642 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4643 } 4644 else 4645 { 4646 $p_header['mtime'] = time(); 4647 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4648 } 4649 4650 // TBC 4651 //for(reset($v_data); $key = key($v_data); next($v_data)) { 4652 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Attribut[$key] = ".$v_data[$key]); 4653 //} 4654 4655 // ----- Set the stored filename 4656 $p_header['stored_filename'] = $p_header['filename']; 4657 4658 // ----- Set the status field 4659 $p_header['status'] = "ok"; 4660 4661 // ----- Return 4662 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4663 return $v_result; 4663 4664 } 4664 4665 // -------------------------------------------------------------------------------- … … 4672 4673 function privReadCentralFileHeader(&$p_header) 4673 4674 { 4674 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadCentralFileHeader", "");4675 $v_result=1;4676 4677 // ----- Read the 4 bytes signature4678 $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 signature4684 if ($v_data['id'] != 0x02014b50)4685 {4686 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid Central Dir File signature");4687 4688 // ----- Error log4689 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');4690 4691 // ----- Return4692 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());4693 return PclZip::errorCode();4694 }4695 4696 // ----- Read the first 42 bytes of the header4697 $v_binary_data = fread($this->zip_fd, 42);4698 4699 // ----- Look for invalid block size4700 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 log4707 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));4708 4709 // ----- Return4710 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());4711 return PclZip::errorCode();4712 }4713 4714 // ----- Extract the values4715 //--(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 filename4720 //--(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 else4724 $p_header['filename'] = '';4725 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Filename : \''.$p_header['filename'].'\'');4726 4727 // ----- Get extra4728 //--(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 else4732 $p_header['extra'] = '';4733 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Extra : \''.$p_header['extra'].'\'');4734 4735 // ----- Get comment4736 //--(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 else4740 $p_header['comment'] = '';4741 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Comment : \''.$p_header['comment'].'\'');4742 4743 // ----- Extract properties4744 //--(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 format4753 //if ($p_header['mdate'] && $p_header['mtime'])4754 // TBC : bug : this was ignoring time with 0/0/04755 if (1)4756 {4757 // ----- Extract time4758 $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 date4763 $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 format4768 $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 else4773 {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 filename4779 $p_header['stored_filename'] = $p_header['filename'];4780 4781 // ----- Set default status to ok4782 $p_header['status'] = 'ok';4783 4784 // ----- Look if it is a directory4785 //--(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 // ----- Return4796 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4797 return $v_result;4675 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadCentralFileHeader", ""); 4676 $v_result=1; 4677 4678 // ----- Read the 4 bytes signature 4679 $v_binary_data = @fread($this->zip_fd, 4); 4680 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); 4681 $v_data = unpack('Vid', $v_binary_data); 4682 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); 4683 4684 // ----- Check signature 4685 if ($v_data['id'] != 0x02014b50) 4686 { 4687 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid Central Dir File signature"); 4688 4689 // ----- Error log 4690 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); 4691 4692 // ----- Return 4693 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4694 return PclZip::errorCode(); 4695 } 4696 4697 // ----- Read the first 42 bytes of the header 4698 $v_binary_data = fread($this->zip_fd, 42); 4699 4700 // ----- Look for invalid block size 4701 if (strlen($v_binary_data) != 42) 4702 { 4703 $p_header['filename'] = ""; 4704 $p_header['status'] = "invalid_header"; 4705 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data)); 4706 4707 // ----- Error log 4708 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); 4709 4710 // ----- Return 4711 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4712 return PclZip::errorCode(); 4713 } 4714 4715 // ----- Extract the values 4716 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header : '".$v_binary_data."'"); 4717 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header (Hex) : '".bin2hex($v_binary_data)."'"); 4718 $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); 4719 4720 // ----- Get filename 4721 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File name length : ".$p_header['filename_len']); 4722 if ($p_header['filename_len'] != 0) 4723 $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); 4724 else 4725 $p_header['filename'] = ''; 4726 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Filename : \''.$p_header['filename'].'\''); 4727 4728 // ----- Get extra 4729 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Extra length : ".$p_header['extra_len']); 4730 if ($p_header['extra_len'] != 0) 4731 $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); 4732 else 4733 $p_header['extra'] = ''; 4734 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Extra : \''.$p_header['extra'].'\''); 4735 4736 // ----- Get comment 4737 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Comment length : ".$p_header['comment_len']); 4738 if ($p_header['comment_len'] != 0) 4739 $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); 4740 else 4741 $p_header['comment'] = ''; 4742 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Comment : \''.$p_header['comment'].'\''); 4743 4744 // ----- Extract properties 4745 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version : \''.($p_header['version']/10).'.'.($p_header['version']%10).'\''); 4746 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\''); 4747 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Size : \''.$p_header['size'].'\''); 4748 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Compressed Size : \''.$p_header['compressed_size'].'\''); 4749 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); 4750 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Flag : \''.$p_header['flag'].'\''); 4751 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Offset : \''.$p_header['offset'].'\''); 4752 4753 // ----- Recuperate date in UNIX format 4754 //if ($p_header['mdate'] && $p_header['mtime']) 4755 // TBC : bug : this was ignoring time with 0/0/0 4756 if (1) 4757 { 4758 // ----- Extract time 4759 $v_hour = ($p_header['mtime'] & 0xF800) >> 11; 4760 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; 4761 $v_seconde = ($p_header['mtime'] & 0x001F)*2; 4762 4763 // ----- Extract date 4764 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; 4765 $v_month = ($p_header['mdate'] & 0x01E0) >> 5; 4766 $v_day = $p_header['mdate'] & 0x001F; 4767 4768 // ----- Get UNIX date format 4769 $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 4770 4771 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4772 } 4773 else 4774 { 4775 $p_header['mtime'] = time(); 4776 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4777 } 4778 4779 // ----- Set the stored filename 4780 $p_header['stored_filename'] = $p_header['filename']; 4781 4782 // ----- Set default status to ok 4783 $p_header['status'] = 'ok'; 4784 4785 // ----- Look if it is a directory 4786 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Internal (Hex) : '".sprintf("Ox%04X", $p_header['internal'])."'"); 4787 //--(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').')'); 4788 if (substr($p_header['filename'], -1) == '/') { 4789 //$p_header['external'] = 0x41FF0010; 4790 $p_header['external'] = 0x00000010; 4791 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Force folder external : \''.sprintf("Ox%04X", $p_header['external']).'\''); 4792 } 4793 4794 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Header of filename : \''.$p_header['filename'].'\''); 4795 4796 // ----- Return 4797 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4798 return $v_result; 4798 4799 } 4799 4800 // -------------------------------------------------------------------------------- … … 4809 4810 function privCheckFileHeaders(&$p_local_header, &$p_central_header) 4810 4811 { 4811 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFileHeaders", "");4812 $v_result=1;4812 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFileHeaders", ""); 4813 $v_result=1; 4813 4814 4814 4815 // ----- Check the static values 4815 4816 // TBC 4816 4817 if ($p_local_header['filename'] != $p_central_header['filename']) { 4817 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename" : TBC To Be Completed');4818 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename" : TBC To Be Completed'); 4818 4819 } 4819 4820 if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { 4820 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "version_extracted" : TBC To Be Completed');4821 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "version_extracted" : TBC To Be Completed'); 4821 4822 } 4822 4823 if ($p_local_header['flag'] != $p_central_header['flag']) { 4823 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "flag" : TBC To Be Completed');4824 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "flag" : TBC To Be Completed'); 4824 4825 } 4825 4826 if ($p_local_header['compression'] != $p_central_header['compression']) { 4826 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "compression" : TBC To Be Completed');4827 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "compression" : TBC To Be Completed'); 4827 4828 } 4828 4829 if ($p_local_header['mtime'] != $p_central_header['mtime']) { 4829 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "mtime" : TBC To Be Completed');4830 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "mtime" : TBC To Be Completed'); 4830 4831 } 4831 4832 if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { 4832 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename_len" : TBC To Be Completed');4833 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename_len" : TBC To Be Completed'); 4833 4834 } 4834 4835 4835 4836 // ----- Look for flag bit 3 4836 4837 if (($p_local_header['flag'] & 8) == 8) { 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']).'\'');4838 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Purpose bit flag bit 3 set !'); 4839 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'File size, compression size and crc found in central header'); 4840 $p_local_header['size'] = $p_central_header['size']; 4841 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_local_header['size'].'\''); 4842 $p_local_header['compressed_size'] = $p_central_header['compressed_size']; 4843 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_local_header['compressed_size'].'\''); 4844 $p_local_header['crc'] = $p_central_header['crc']; 4845 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_local_header['crc']).'\''); 4845 4846 } 4846 4847 4847 // ----- Return4848 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);4849 return $v_result;4848 // ----- Return 4849 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4850 return $v_result; 4850 4851 } 4851 4852 // -------------------------------------------------------------------------------- … … 4859 4860 function privReadEndCentralDir(&$p_central_dir) 4860 4861 { 4861 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadEndCentralDir", "");4862 $v_result=1;4863 4864 // ----- Go to the end of the zip file4865 $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 log4872 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');4873 4874 // ----- Return4875 //--(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 end4881 $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 log4889 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');4890 4891 // ----- Return4892 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());4893 return PclZip::errorCode();4894 }4895 4896 // ----- Read for bytes4897 $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 signature4903 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 Record4912 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 log4921 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');4922 4923 // ----- Return4924 //--(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 signature4930 $v_pos = ftell($this->zip_fd);4931 $v_bytes = 0x00000000;4932 while ($v_pos < $v_size)4933 {4934 // ----- Read a byte4935 $v_byte = @fread($this->zip_fd, 1);4936 4937 // ----- Add the byte4938 $v_bytes = ($v_bytes << 8) | Ord($v_byte);4939 4940 // ----- Compare the bytes4941 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 dir4952 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 log4957 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");4958 4959 // ----- Return4960 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());4961 return PclZip::errorCode();4962 }4963 }4964 4965 // ----- Read the first 18 bytes of the header4966 $v_binary_data = fread($this->zip_fd, 18);4967 4968 // ----- Look for invalid block size4969 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 log4974 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));4975 4976 // ----- Return4977 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());4978 return PclZip::errorCode();4979 }4980 4981 // ----- Extract the values4982 ////--(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 size4987 //--(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.");4862 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadEndCentralDir", ""); 4863 $v_result=1; 4864 4865 // ----- Go to the end of the zip file 4866 $v_size = filesize($this->zipname); 4867 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size of the file :$v_size"); 4868 @fseek($this->zip_fd, $v_size); 4869 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position at end of zip file : \''.ftell($this->zip_fd).'\''); 4870 if (@ftell($this->zip_fd) != $v_size) 4871 { 4872 // ----- Error log 4873 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); 4874 4875 // ----- Return 4876 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4877 return PclZip::errorCode(); 4878 } 4879 4880 // ----- First try : look if this is an archive with no commentaries (most of the time) 4881 // in this case the end of central dir is at 22 bytes of the file end 4882 $v_found = 0; 4883 if ($v_size > 26) { 4884 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Look for central dir with no comment'); 4885 @fseek($this->zip_fd, $v_size-22); 4886 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after min central position : \''.ftell($this->zip_fd).'\''); 4887 if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) 4888 { 4889 // ----- Error log 4890 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); 4891 4892 // ----- Return 4893 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4894 return PclZip::errorCode(); 4895 } 4896 4897 // ----- Read for bytes 4898 $v_binary_data = @fread($this->zip_fd, 4); 4899 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); 4900 $v_data = @unpack('Vid', $v_binary_data); 4901 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); 4902 4903 // ----- Check signature 4904 if ($v_data['id'] == 0x06054b50) { 4905 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found central dir at the default position."); 4906 $v_found = 1; 4907 } 4908 4909 $v_pos = ftell($this->zip_fd); 4910 } 4911 4912 // ----- Go back to the maximum possible size of the Central Dir End Record 4913 if (!$v_found) { 4914 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Start extended search of end central dir'); 4915 $v_maximum_size = 65557; // 0xFFFF + 22; 4916 if ($v_maximum_size > $v_size) 4917 $v_maximum_size = $v_size; 4918 @fseek($this->zip_fd, $v_size-$v_maximum_size); 4919 if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) 4920 { 4921 // ----- Error log 4922 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); 4923 4924 // ----- Return 4925 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4926 return PclZip::errorCode(); 4927 } 4928 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after max central position : \''.ftell($this->zip_fd).'\''); 4929 4930 // ----- Read byte per byte in order to find the signature 4931 $v_pos = ftell($this->zip_fd); 4932 $v_bytes = 0x00000000; 4933 while ($v_pos < $v_size) 4934 { 4935 // ----- Read a byte 4936 $v_byte = @fread($this->zip_fd, 1); 4937 4938 // ----- Add the byte 4939 $v_bytes = ($v_bytes << 8) | Ord($v_byte); 4940 4941 // ----- Compare the bytes 4942 if ($v_bytes == 0x504b0506) 4943 { 4944 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Found End Central Dir signature at position : \''.ftell($this->zip_fd).'\''); 4945 $v_pos++; 4946 break; 4947 } 4948 4949 $v_pos++; 4950 } 4951 4952 // ----- Look if not found end of central dir 4953 if ($v_pos == $v_size) 4954 { 4955 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to find End of Central Dir Record signature"); 4956 4957 // ----- Error log 4958 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); 4959 4960 // ----- Return 4961 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4962 return PclZip::errorCode(); 4963 } 4964 } 4965 4966 // ----- Read the first 18 bytes of the header 4967 $v_binary_data = fread($this->zip_fd, 18); 4968 4969 // ----- Look for invalid block size 4970 if (strlen($v_binary_data) != 18) 4971 { 4972 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); 4973 4974 // ----- Error log 4975 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); 4976 4977 // ----- Return 4978 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 4979 return PclZip::errorCode(); 4980 } 4981 4982 // ----- Extract the values 4983 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record : '".$v_binary_data."'"); 4984 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record (Hex) : '".bin2hex($v_binary_data)."'"); 4985 $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); 4986 4987 // ----- Check the global size 4988 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Comment length : ".$v_data['comment_size']); 4989 if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { 4990 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The central dir is not at the end of the archive. Some trailing bytes exists after the archive."); 4990 4991 4991 4992 // ----- Removed in release 2.2 see readme file … … 4994 4995 // While decrypted, zip has training 0 bytes 4995 4996 if (0) { 4996 // ----- Error log4997 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,4998 'The central dir is not at the end of the archive.'4997 // ----- Error log 4998 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 4999 'The central dir is not at the end of the archive.' 4999 5000 .' Some trailing bytes exists after the archive.'); 5000 5001 5001 // ----- Return5002 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());5003 return PclZip::errorCode();5002 // ----- Return 5003 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5004 return PclZip::errorCode(); 5004 5005 } 5005 }5006 5007 // ----- Get comment5008 //--(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 else5013 $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 // TBC5030 //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 // ----- Return5035 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5036 return $v_result;5006 } 5007 5008 // ----- Get comment 5009 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment size : \''.$v_data['comment_size'].'\''); 5010 if ($v_data['comment_size'] != 0) { 5011 $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); 5012 } 5013 else 5014 $p_central_dir['comment'] = ''; 5015 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment : \''.$p_central_dir['comment'].'\''); 5016 5017 $p_central_dir['entries'] = $v_data['entries']; 5018 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries : \''.$p_central_dir['entries'].'\''); 5019 $p_central_dir['disk_entries'] = $v_data['disk_entries']; 5020 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries for this disk : \''.$p_central_dir['disk_entries'].'\''); 5021 $p_central_dir['offset'] = $v_data['offset']; 5022 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Offset of Central Dir : \''.$p_central_dir['offset'].'\''); 5023 $p_central_dir['size'] = $v_data['size']; 5024 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size of Central Dir : \''.$p_central_dir['size'].'\''); 5025 $p_central_dir['disk'] = $v_data['disk']; 5026 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Disk number : \''.$p_central_dir['disk'].'\''); 5027 $p_central_dir['disk_start'] = $v_data['disk_start']; 5028 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Start disk number : \''.$p_central_dir['disk_start'].'\''); 5029 5030 // TBC 5031 //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) { 5032 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "central_dir[$key] = ".$p_central_dir[$key]); 5033 //} 5034 5035 // ----- Return 5036 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5037 return $v_result; 5037 5038 } 5038 5039 // -------------------------------------------------------------------------------- … … 5046 5047 function privDeleteByRule(&$p_result_list, &$p_options) 5047 5048 { 5048 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByRule", "");5049 $v_result=1;5050 $v_list_detail = array();5051 5052 // ----- Open the zip file5053 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");5054 if (($v_result=$this->privOpenFd('rb')) != 1)5055 {5056 // ----- Return5057 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5058 return $v_result;5059 }5060 5061 // ----- Read the central directory informations5062 $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 File5071 //--(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 files5076 // ----- Start at beginning of Central Dir5077 $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 file5084 $this->privCloseFd();5085 5086 // ----- Error log5087 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');5088 5089 // ----- Return5090 //--(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 entry5096 $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 header5103 $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 file5107 $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 index5116 $v_header_list[$v_nb_extracted]['index'] = $i;5117 5118 // ----- Look for the specific extract rules5119 $v_found = false;5120 5121 // ----- Look for extract by name rule5122 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 list5127 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 directory5131 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 path5135 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 filename5147 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 rule5155 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 rule5166 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 rule5177 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 list5182 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 deletion5206 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 else5212 {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 deleted5219 if ($v_nb_extracted > 0) {5220 5221 // ----- Creates a temporay file5222 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';5223 5224 // ----- Creates a temporary zip archive5225 $v_temp_zip = new PclZip($v_zip_temp_name);5226 5227 // ----- Open the temporary zip file in write mode5228 //--(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 // ----- Return5233 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5234 return $v_result;5235 }5236 5237 // ----- Look which file need to be kept5238 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 header5242 //--(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 file5248 $this->privCloseFd();5249 $v_temp_zip->privCloseFd();5250 @unlink($v_zip_temp_name);5251 5252 // ----- Error log5253 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');5254 5255 // ----- Return5256 //--(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 header5262 $v_local_header = array();5263 if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {5264 // ----- Close the zip file5265 $this->privCloseFd();5266 $v_temp_zip->privCloseFd();5267 @unlink($v_zip_temp_name);5268 5269 // ----- Return5270 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5271 return $v_result;5272 }5273 5274 // ----- Check that local file header is same as central file header5275 if ($this->privCheckFileHeaders($v_local_header,5276 $v_header_list[$i]) != 1) {5277 // TBC5278 }5279 unset($v_local_header);5280 5281 // ----- Write the file header5282 if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {5283 // ----- Close the zip file5284 $this->privCloseFd();5285 $v_temp_zip->privCloseFd();5286 @unlink($v_zip_temp_name);5287 5288 // ----- Return5289 //--(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 block5295 if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {5296 // ----- Close the zip file5297 $this->privCloseFd();5298 $v_temp_zip->privCloseFd();5299 @unlink($v_zip_temp_name);5300 5301 // ----- Return5302 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5303 return $v_result;5304 }5305 }5306 5307 // ----- Store the offset of the central dir5308 $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 header5312 //--(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 header5315 //--(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 // ----- Return5322 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5323 return $v_result;5324 }5325 5326 // ----- Transform the header to a 'usable' info5327 $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 comment5333 $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 header5339 $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;5340 5341 // ----- Create the central dir footer5342 if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {5343 // ----- Reset the file list5344 unset($v_header_list);5345 $v_temp_zip->privCloseFd();5346 $this->privCloseFd();5347 @unlink($v_zip_temp_name);5348 5349 // ----- Return5350 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5351 return $v_result;5352 }5353 5354 // ----- Close5355 $v_temp_zip->privCloseFd();5356 $this->privCloseFd();5357 5358 // ----- Delete the zip file5359 // TBC : I should test the result ...5360 @unlink($this->zipname);5361 5362 // ----- Rename the temporary file5363 // 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 archive5368 unset($v_temp_zip);5369 }5370 5371 // ----- Remove every files : reset the file5372 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 // ----- Return5389 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5390 return $v_result;5049 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByRule", ""); 5050 $v_result=1; 5051 $v_list_detail = array(); 5052 5053 // ----- Open the zip file 5054 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5055 if (($v_result=$this->privOpenFd('rb')) != 1) 5056 { 5057 // ----- Return 5058 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5059 return $v_result; 5060 } 5061 5062 // ----- Read the central directory informations 5063 $v_central_dir = array(); 5064 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 5065 { 5066 $this->privCloseFd(); 5067 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5068 return $v_result; 5069 } 5070 5071 // ----- Go to beginning of File 5072 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); 5073 @rewind($this->zip_fd); 5074 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); 5075 5076 // ----- Scan all the files 5077 // ----- Start at beginning of Central Dir 5078 $v_pos_entry = $v_central_dir['offset']; 5079 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); 5080 @rewind($this->zip_fd); 5081 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); 5082 if (@fseek($this->zip_fd, $v_pos_entry)) 5083 { 5084 // ----- Close the zip file 5085 $this->privCloseFd(); 5086 5087 // ----- Error log 5088 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 5089 5090 // ----- Return 5091 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5092 return PclZip::errorCode(); 5093 } 5094 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); 5095 5096 // ----- Read each entry 5097 $v_header_list = array(); 5098 $j_start = 0; 5099 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) 5100 { 5101 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry (index '$i')"); 5102 5103 // ----- Read the file header 5104 $v_header_list[$v_nb_extracted] = array(); 5105 if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) 5106 { 5107 // ----- Close the zip file 5108 $this->privCloseFd(); 5109 5110 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5111 return $v_result; 5112 } 5113 5114 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename (index '$i') : '".$v_header_list[$v_nb_extracted]['stored_filename']."'"); 5115 5116 // ----- Store the index 5117 $v_header_list[$v_nb_extracted]['index'] = $i; 5118 5119 // ----- Look for the specific extract rules 5120 $v_found = false; 5121 5122 // ----- Look for extract by name rule 5123 if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) 5124 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { 5125 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'"); 5126 5127 // ----- Look if the filename is in the list 5128 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { 5129 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'"); 5130 5131 // ----- Look for a directory 5132 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { 5133 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory"); 5134 5135 // ----- Look if the directory is in the filename path 5136 if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) 5137 && (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])) { 5138 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path"); 5139 $v_found = true; 5140 } 5141 elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ 5142 && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { 5143 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The entry is the searched directory"); 5144 $v_found = true; 5145 } 5146 } 5147 // ----- Look for a filename 5148 elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { 5149 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one."); 5150 $v_found = true; 5151 } 5152 } 5153 } 5154 5155 // ----- Look for extract by ereg rule 5156 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) 5157 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { 5158 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'"); 5159 5160 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { 5161 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); 5162 $v_found = true; 5163 } 5164 } 5165 5166 // ----- Look for extract by preg rule 5167 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) 5168 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { 5169 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'"); 5170 5171 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { 5172 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); 5173 $v_found = true; 5174 } 5175 } 5176 5177 // ----- Look for extract by index rule 5178 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) 5179 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { 5180 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'"); 5181 5182 // ----- Look if the index is in the list 5183 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { 5184 //--(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']."]"); 5185 5186 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { 5187 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range"); 5188 $v_found = true; 5189 } 5190 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { 5191 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop"); 5192 $j_start = $j+1; 5193 } 5194 5195 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { 5196 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop"); 5197 break; 5198 } 5199 } 5200 } 5201 else { 5202 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "No argument mean remove all file"); 5203 $v_found = true; 5204 } 5205 5206 // ----- Look for deletion 5207 if ($v_found) 5208 { 5209 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' need to be deleted"); 5210 unset($v_header_list[$v_nb_extracted]); 5211 } 5212 else 5213 { 5214 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' will not be deleted"); 5215 $v_nb_extracted++; 5216 } 5217 } 5218 5219 // ----- Look if something need to be deleted 5220 if ($v_nb_extracted > 0) { 5221 5222 // ----- Creates a temporay file 5223 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; 5224 5225 // ----- Creates a temporary zip archive 5226 $v_temp_zip = new PclZip($v_zip_temp_name); 5227 5228 // ----- Open the temporary zip file in write mode 5229 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary write mode"); 5230 if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) { 5231 $this->privCloseFd(); 5232 5233 // ----- Return 5234 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5235 return $v_result; 5236 } 5237 5238 // ----- Look which file need to be kept 5239 for ($i=0; $i<sizeof($v_header_list); $i++) { 5240 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Keep entry index '$i' : '".$v_header_list[$i]['filename']."'"); 5241 5242 // ----- Calculate the position of the header 5243 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset='". $v_header_list[$i]['offset']."'"); 5244 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); 5245 @rewind($this->zip_fd); 5246 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); 5247 if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { 5248 // ----- Close the zip file 5249 $this->privCloseFd(); 5250 $v_temp_zip->privCloseFd(); 5251 @unlink($v_zip_temp_name); 5252 5253 // ----- Error log 5254 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); 5255 5256 // ----- Return 5257 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5258 return PclZip::errorCode(); 5259 } 5260 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); 5261 5262 // ----- Read the file header 5263 $v_local_header = array(); 5264 if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) { 5265 // ----- Close the zip file 5266 $this->privCloseFd(); 5267 $v_temp_zip->privCloseFd(); 5268 @unlink($v_zip_temp_name); 5269 5270 // ----- Return 5271 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5272 return $v_result; 5273 } 5274 5275 // ----- Check that local file header is same as central file header 5276 if ($this->privCheckFileHeaders($v_local_header, 5277 $v_header_list[$i]) != 1) { 5278 // TBC 5279 } 5280 unset($v_local_header); 5281 5282 // ----- Write the file header 5283 if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) { 5284 // ----- Close the zip file 5285 $this->privCloseFd(); 5286 $v_temp_zip->privCloseFd(); 5287 @unlink($v_zip_temp_name); 5288 5289 // ----- Return 5290 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5291 return $v_result; 5292 } 5293 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset for this file is '".$v_header_list[$i]['offset']."'"); 5294 5295 // ----- Read/write the data block 5296 if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) { 5297 // ----- Close the zip file 5298 $this->privCloseFd(); 5299 $v_temp_zip->privCloseFd(); 5300 @unlink($v_zip_temp_name); 5301 5302 // ----- Return 5303 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5304 return $v_result; 5305 } 5306 } 5307 5308 // ----- Store the offset of the central dir 5309 $v_offset = @ftell($v_temp_zip->zip_fd); 5310 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "New offset of central dir : $v_offset"); 5311 5312 // ----- Re-Create the Central Dir files header 5313 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the new central directory"); 5314 for ($i=0; $i<sizeof($v_header_list); $i++) { 5315 // ----- Create the file header 5316 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset of file : ".$v_header_list[$i]['offset']); 5317 if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) { 5318 $v_temp_zip->privCloseFd(); 5319 $this->privCloseFd(); 5320 @unlink($v_zip_temp_name); 5321 5322 // ----- Return 5323 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5324 return $v_result; 5325 } 5326 5327 // ----- Transform the header to a 'usable' info 5328 $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); 5329 } 5330 5331 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the central directory footer"); 5332 5333 // ----- Zip file comment 5334 $v_comment = ''; 5335 if (isset($p_options[PCLZIP_OPT_COMMENT])) { 5336 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; 5337 } 5338 5339 // ----- Calculate the size of the central header 5340 $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset; 5341 5342 // ----- Create the central dir footer 5343 if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) { 5344 // ----- Reset the file list 5345 unset($v_header_list); 5346 $v_temp_zip->privCloseFd(); 5347 $this->privCloseFd(); 5348 @unlink($v_zip_temp_name); 5349 5350 // ----- Return 5351 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5352 return $v_result; 5353 } 5354 5355 // ----- Close 5356 $v_temp_zip->privCloseFd(); 5357 $this->privCloseFd(); 5358 5359 // ----- Delete the zip file 5360 // TBC : I should test the result ... 5361 @unlink($this->zipname); 5362 5363 // ----- Rename the temporary file 5364 // TBC : I should test the result ... 5365 //@rename($v_zip_temp_name, $this->zipname); 5366 PclZipUtilRename($v_zip_temp_name, $this->zipname); 5367 5368 // ----- Destroy the temporary archive 5369 unset($v_temp_zip); 5370 } 5371 5372 // ----- Remove every files : reset the file 5373 else if ($v_central_dir['entries'] != 0) { 5374 $this->privCloseFd(); 5375 5376 if (($v_result = $this->privOpenFd('wb')) != 1) { 5377 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5378 return $v_result; 5379 } 5380 5381 if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) { 5382 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5383 return $v_result; 5384 } 5385 5386 $this->privCloseFd(); 5387 } 5388 5389 // ----- Return 5390 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5391 return $v_result; 5391 5392 } 5392 5393 // -------------------------------------------------------------------------------- … … 5400 5401 // $p_dir : Directory path to check. 5401 5402 // Return Values : 5402 // 1 : OK5403 // 1 : OK 5403 5404 // -1 : Unable to create directory 5404 5405 // -------------------------------------------------------------------------------- 5405 5406 function privDirCheck($p_dir, $p_is_dir=false) 5406 5407 { 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 availability5419 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 directory5426 $p_parent_dir = dirname($p_dir);5427 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Parent directory is '$p_parent_dir'");5428 5429 // ----- Just a check5430 if ($p_parent_dir != $p_dir)5431 {5432 // ----- Look for parent directory5433 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 directory5444 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Create directory '$p_dir'");5445 if (!@mkdir($p_dir, 0777))5446 {5447 // ----- Error log5448 PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");5449 5450 // ----- Return5451 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());5452 return PclZip::errorCode();5453 }5454 5455 // ----- Return5456 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result, "Directory '$p_dir' created");5457 return $v_result;5408 $v_result = 1; 5409 5410 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDirCheck", "entry='$p_dir', is_dir='".($p_is_dir?"true":"false")."'"); 5411 5412 // ----- Remove the final '/' 5413 if (($p_is_dir) && (substr($p_dir, -1)=='/')) 5414 { 5415 $p_dir = substr($p_dir, 0, strlen($p_dir)-1); 5416 } 5417 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for entry '$p_dir'"); 5418 5419 // ----- Check the directory availability 5420 if ((is_dir($p_dir)) || ($p_dir == "")) 5421 { 5422 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, "'$p_dir' is a directory"); 5423 return 1; 5424 } 5425 5426 // ----- Extract parent directory 5427 $p_parent_dir = dirname($p_dir); 5428 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Parent directory is '$p_parent_dir'"); 5429 5430 // ----- Just a check 5431 if ($p_parent_dir != $p_dir) 5432 { 5433 // ----- Look for parent directory 5434 if ($p_parent_dir != "") 5435 { 5436 if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) 5437 { 5438 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5439 return $v_result; 5440 } 5441 } 5442 } 5443 5444 // ----- Create the directory 5445 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Create directory '$p_dir'"); 5446 if (!@mkdir($p_dir, 0777)) 5447 { 5448 // ----- Error log 5449 PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); 5450 5451 // ----- Return 5452 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5453 return PclZip::errorCode(); 5454 } 5455 5456 // ----- Return 5457 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result, "Directory '$p_dir' created"); 5458 return $v_result; 5458 5459 } 5459 5460 // -------------------------------------------------------------------------------- … … 5468 5469 function privMerge(&$p_archive_to_add) 5469 5470 { 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 exists5474 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 success5479 $v_result = 1;5480 5481 // ----- Return5482 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5483 return $v_result;5484 }5485 5486 // ----- Look if the archive exists5487 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 duplicate5492 $v_result = $this->privDuplicate($p_archive_to_add->zipname);5493 5494 // ----- Return5495 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5496 return $v_result;5497 }5498 5499 // ----- Open the zip file5500 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");5501 if (($v_result=$this->privOpenFd('rb')) != 1)5502 {5503 // ----- Return5504 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5505 return $v_result;5506 }5507 5508 // ----- Read the central directory informations5509 $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 File5518 //--(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 file5523 //--(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 // ----- Return5529 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5530 return $v_result;5531 }5532 5533 // ----- Read the central directory informations5534 $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 File5545 //--(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 file5550 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';5551 5552 // ----- Open the temporary file in write mode5553 //--(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 // ----- Return5562 //--(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 file5567 // TBC : Here I should better append the file and go back to erase the central dir5568 $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 file5579 $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 dir5590 $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 archive5594 $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_add5605 $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 comments5616 $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];5617 5618 // ----- Calculate the size of the (new) central header5619 $v_size = @ftell($v_zip_temp_fd)-$v_offset;5620 5621 // ----- Swap the file descriptor5622 // Here is a trick : I swap the temporary fd with the zip fd, in order to use5623 // the following methods on the temporary fil and not the real archive fd5624 $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 footer5629 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 list5637 unset($v_header_list);5638 5639 // ----- Return5640 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5641 return $v_result;5642 }5643 5644 // ----- Swap back the file descriptor5645 $v_swap = $this->zip_fd;5646 $this->zip_fd = $v_zip_temp_fd;5647 $v_zip_temp_fd = $v_swap;5648 5649 // ----- Close5650 $this->privCloseFd();5651 $p_archive_to_add->privCloseFd();5652 5653 // ----- Close the temporary file5654 @fclose($v_zip_temp_fd);5655 5656 // ----- Delete the zip file5657 // TBC : I should test the result ...5658 @unlink($this->zipname);5659 5660 // ----- Rename the temporary file5661 // TBC : I should test the result ...5662 //@rename($v_zip_temp_name, $this->zipname);5663 PclZipUtilRename($v_zip_temp_name, $this->zipname);5664 5665 // ----- Return5666 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5667 return $v_result;5471 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privMerge", "archive='".$p_archive_to_add->zipname."'"); 5472 $v_result=1; 5473 5474 // ----- Look if the archive_to_add exists 5475 if (!is_file($p_archive_to_add->zipname)) 5476 { 5477 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to add does not exist. End of merge."); 5478 5479 // ----- Nothing to merge, so merge is a success 5480 $v_result = 1; 5481 5482 // ----- Return 5483 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5484 return $v_result; 5485 } 5486 5487 // ----- Look if the archive exists 5488 if (!is_file($this->zipname)) 5489 { 5490 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, duplicate the archive_to_add."); 5491 5492 // ----- Do a duplicate 5493 $v_result = $this->privDuplicate($p_archive_to_add->zipname); 5494 5495 // ----- Return 5496 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5497 return $v_result; 5498 } 5499 5500 // ----- Open the zip file 5501 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5502 if (($v_result=$this->privOpenFd('rb')) != 1) 5503 { 5504 // ----- Return 5505 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5506 return $v_result; 5507 } 5508 5509 // ----- Read the central directory informations 5510 $v_central_dir = array(); 5511 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) 5512 { 5513 $this->privCloseFd(); 5514 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5515 return $v_result; 5516 } 5517 5518 // ----- Go to beginning of File 5519 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'"); 5520 @rewind($this->zip_fd); 5521 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'"); 5522 5523 // ----- Open the archive_to_add file 5524 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open archive_to_add in binary read mode"); 5525 if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) 5526 { 5527 $this->privCloseFd(); 5528 5529 // ----- Return 5530 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5531 return $v_result; 5532 } 5533 5534 // ----- Read the central directory informations 5535 $v_central_dir_to_add = array(); 5536 if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) 5537 { 5538 $this->privCloseFd(); 5539 $p_archive_to_add->privCloseFd(); 5540 5541 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5542 return $v_result; 5543 } 5544 5545 // ----- Go to beginning of File 5546 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'"); 5547 @rewind($p_archive_to_add->zip_fd); 5548 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'"); 5549 5550 // ----- Creates a temporay file 5551 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; 5552 5553 // ----- Open the temporary file in write mode 5554 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5555 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) 5556 { 5557 $this->privCloseFd(); 5558 $p_archive_to_add->privCloseFd(); 5559 5560 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); 5561 5562 // ----- Return 5563 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5564 return PclZip::errorCode(); 5565 } 5566 5567 // ----- Copy the files from the archive to the temporary file 5568 // TBC : Here I should better append the file and go back to erase the central dir 5569 $v_size = $v_central_dir['offset']; 5570 while ($v_size != 0) 5571 { 5572 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5573 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5574 $v_buffer = fread($this->zip_fd, $v_read_size); 5575 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 5576 $v_size -= $v_read_size; 5577 } 5578 5579 // ----- Copy the files from the archive_to_add into the temporary file 5580 $v_size = $v_central_dir_to_add['offset']; 5581 while ($v_size != 0) 5582 { 5583 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5584 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5585 $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); 5586 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 5587 $v_size -= $v_read_size; 5588 } 5589 5590 // ----- Store the offset of the central dir 5591 $v_offset = @ftell($v_zip_temp_fd); 5592 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset"); 5593 5594 // ----- Copy the block of file headers from the old archive 5595 $v_size = $v_central_dir['size']; 5596 while ($v_size != 0) 5597 { 5598 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5599 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5600 $v_buffer = @fread($this->zip_fd, $v_read_size); 5601 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 5602 $v_size -= $v_read_size; 5603 } 5604 5605 // ----- Copy the block of file headers from the archive_to_add 5606 $v_size = $v_central_dir_to_add['size']; 5607 while ($v_size != 0) 5608 { 5609 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5610 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 5611 $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); 5612 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); 5613 $v_size -= $v_read_size; 5614 } 5615 5616 // ----- Merge the file comments 5617 $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment']; 5618 5619 // ----- Calculate the size of the (new) central header 5620 $v_size = @ftell($v_zip_temp_fd)-$v_offset; 5621 5622 // ----- Swap the file descriptor 5623 // Here is a trick : I swap the temporary fd with the zip fd, in order to use 5624 // the following methods on the temporary fil and not the real archive fd 5625 $v_swap = $this->zip_fd; 5626 $this->zip_fd = $v_zip_temp_fd; 5627 $v_zip_temp_fd = $v_swap; 5628 5629 // ----- Create the central dir footer 5630 if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) 5631 { 5632 $this->privCloseFd(); 5633 $p_archive_to_add->privCloseFd(); 5634 @fclose($v_zip_temp_fd); 5635 $this->zip_fd = null; 5636 5637 // ----- Reset the file list 5638 unset($v_header_list); 5639 5640 // ----- Return 5641 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5642 return $v_result; 5643 } 5644 5645 // ----- Swap back the file descriptor 5646 $v_swap = $this->zip_fd; 5647 $this->zip_fd = $v_zip_temp_fd; 5648 $v_zip_temp_fd = $v_swap; 5649 5650 // ----- Close 5651 $this->privCloseFd(); 5652 $p_archive_to_add->privCloseFd(); 5653 5654 // ----- Close the temporary file 5655 @fclose($v_zip_temp_fd); 5656 5657 // ----- Delete the zip file 5658 // TBC : I should test the result ... 5659 @unlink($this->zipname); 5660 5661 // ----- Rename the temporary file 5662 // TBC : I should test the result ... 5663 //@rename($v_zip_temp_name, $this->zipname); 5664 PclZipUtilRename($v_zip_temp_name, $this->zipname); 5665 5666 // ----- Return 5667 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5668 return $v_result; 5668 5669 } 5669 5670 // -------------------------------------------------------------------------------- … … 5677 5678 function privDuplicate($p_archive_filename) 5678 5679 { 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 exists5683 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 // ----- Return5691 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5692 return $v_result;5693 }5694 5695 // ----- Open the zip file5696 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");5697 if (($v_result=$this->privOpenFd('wb')) != 1)5698 {5699 // ----- Return5700 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5701 return $v_result;5702 }5703 5704 // ----- Open the temporary file in write mode5705 //--(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 // ----- Return5713 //--(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 file5718 // TBC : Here I should better append the file and go back to erase the central dir5719 $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 // ----- Close5730 $this->privCloseFd();5731 5732 // ----- Close the temporary file5733 @fclose($v_zip_temp_fd);5734 5735 // ----- Return5736 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5737 return $v_result;5680 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDuplicate", "archive_filename='$p_archive_filename'"); 5681 $v_result=1; 5682 5683 // ----- Look if the $p_archive_filename exists 5684 if (!is_file($p_archive_filename)) 5685 { 5686 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to duplicate does not exist. End of duplicate."); 5687 5688 // ----- Nothing to duplicate, so duplicate is a success. 5689 $v_result = 1; 5690 5691 // ----- Return 5692 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5693 return $v_result; 5694 } 5695 5696 // ----- Open the zip file 5697 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5698 if (($v_result=$this->privOpenFd('wb')) != 1) 5699 { 5700 // ----- Return 5701 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5702 return $v_result; 5703 } 5704 5705 // ----- Open the temporary file in write mode 5706 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); 5707 if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) 5708 { 5709 $this->privCloseFd(); 5710 5711 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); 5712 5713 // ----- Return 5714 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 5715 return PclZip::errorCode(); 5716 } 5717 5718 // ----- Copy the files from the archive to the temporary file 5719 // TBC : Here I should better append the file and go back to erase the central dir 5720 $v_size = filesize($p_archive_filename); 5721 while ($v_size != 0) 5722 { 5723 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 5724 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read $v_read_size bytes"); 5725 $v_buffer = fread($v_zip_temp_fd, $v_read_size); 5726 @fwrite($this->zip_fd, $v_buffer, $v_read_size); 5727 $v_size -= $v_read_size; 5728 } 5729 5730 // ----- Close 5731 $this->privCloseFd(); 5732 5733 // ----- Close the temporary file 5734 @fclose($v_zip_temp_fd); 5735 5736 // ----- Return 5737 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5738 return $v_result; 5738 5739 } 5739 5740 // -------------------------------------------------------------------------------- … … 5746 5747 function privErrorLog($p_error_code=0, $p_error_string='') 5747 5748 { 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 }5749 if (PCLZIP_ERROR_EXTERNAL == 1) { 5750 PclError($p_error_code, $p_error_string); 5751 } 5752 else { 5753 $this->error_code = $p_error_code; 5754 $this->error_string = $p_error_string; 5755 } 5755 5756 } 5756 5757 // -------------------------------------------------------------------------------- … … 5763 5764 function privErrorReset() 5764 5765 { 5765 if (PCLZIP_ERROR_EXTERNAL == 1) {5766 PclErrorReset();5767 }5768 else {5769 $this->error_code = 0;5770 $this->error_string = '';5771 }5766 if (PCLZIP_ERROR_EXTERNAL == 1) { 5767 PclErrorReset(); 5768 } 5769 else { 5770 $this->error_code = 0; 5771 $this->error_string = ''; 5772 } 5772 5773 } 5773 5774 // -------------------------------------------------------------------------------- … … 5781 5782 function privDecrypt($p_encryption_header, &$p_buffer, $p_size, $p_crc) 5782 5783 { 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 // ----- Return5793 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5794 return $v_result;5784 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDecrypt', "size=".$p_size.""); 5785 $v_result=1; 5786 5787 // ----- To Be Modified ;-) 5788 $v_pwd = "test"; 5789 5790 $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header, 5791 $p_crc, $v_pwd); 5792 5793 // ----- Return 5794 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5795 return $v_result; 5795 5796 } 5796 5797 // -------------------------------------------------------------------------------- … … 5804 5805 function privDisableMagicQuotes() 5805 5806 { 5806 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDisableMagicQuotes', "");5807 $v_result=1;5808 5809 // ----- Look if function exists5810 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;5807 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDisableMagicQuotes', ""); 5808 $v_result=1; 5809 5810 // ----- Look if function exists 5811 if ( (!function_exists("get_magic_quotes_runtime")) 5812 || (!function_exists("set_magic_quotes_runtime"))) { 5813 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported"); 5814 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5815 return $v_result; 5815 5816 } 5816 5817 5817 // ----- Look if already done5818 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;5818 // ----- Look if already done 5819 if ($this->magic_quotes_status != -1) { 5820 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote already disabled"); 5821 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5822 return $v_result; 5822 5823 } 5823 5824 5824 5825 // ----- Get and memorize the magic_quote value 5825 5826 $this->magic_quotes_status = @get_magic_quotes_runtime(); 5826 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Current magic_quotes_runtime status is '".($this->magic_quotes_status==0?'disable':'enable')."'");5827 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Current magic_quotes_runtime status is '".($this->magic_quotes_status==0?'disable':'enable')."'"); 5827 5828 5828 5829 // ----- Disable magic_quotes 5829 5830 if ($this->magic_quotes_status == 1) { 5830 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Disable magic_quotes");5831 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Disable magic_quotes"); 5831 5832 @set_magic_quotes_runtime(0); 5832 5833 } 5833 5834 5834 // ----- Return5835 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5836 return $v_result;5835 // ----- Return 5836 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5837 return $v_result; 5837 5838 } 5838 5839 // -------------------------------------------------------------------------------- … … 5846 5847 function privSwapBackMagicQuotes() 5847 5848 { 5848 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privSwapBackMagicQuotes', "");5849 $v_result=1;5850 5851 // ----- Look if function exists5852 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;5849 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privSwapBackMagicQuotes', ""); 5850 $v_result=1; 5851 5852 // ----- Look if function exists 5853 if ( (!function_exists("get_magic_quotes_runtime")) 5854 || (!function_exists("set_magic_quotes_runtime"))) { 5855 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported"); 5856 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5857 return $v_result; 5857 5858 } 5858 5859 5859 // ----- Look if something to do5860 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;5860 // ----- Look if something to do 5861 if ($this->magic_quotes_status != -1) { 5862 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote not modified"); 5863 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5864 return $v_result; 5864 5865 } 5865 5866 5866 5867 // ----- Swap back magic_quotes 5867 5868 if ($this->magic_quotes_status == 1) { 5868 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Enable back magic_quotes");5869 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Enable back magic_quotes"); 5869 5870 @set_magic_quotes_runtime($this->magic_quotes_status); 5870 5871 } 5871 5872 5872 // ----- Return5873 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5874 return $v_result;5873 // ----- Return 5874 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5875 return $v_result; 5875 5876 } 5876 5877 // -------------------------------------------------------------------------------- … … 5888 5889 function PclZipUtilPathReduction($p_dir) 5889 5890 { 5890 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathReduction", "dir='$p_dir'");5891 $v_result = "";5892 5893 // ----- Look for not empty path5894 if ($p_dir != "") {5895 // ----- Explode path by directory names5896 $v_list = explode("/", $p_dir);5897 5898 // ----- Study directories from last to first5899 $v_skip = 0;5900 for ($i=sizeof($v_list)-1; $i>=0; $i--) {5901 // ----- Look for current path5902 if ($v_list[$i] == ".") {5903 // ----- Ignore this directory5904 // Should be the first $i=0, but no check is done5905 }5906 else if ($v_list[$i] == "..") {5891 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathReduction", "dir='$p_dir'"); 5892 $v_result = ""; 5893 5894 // ----- Look for not empty path 5895 if ($p_dir != "") { 5896 // ----- Explode path by directory names 5897 $v_list = explode("/", $p_dir); 5898 5899 // ----- Study directories from last to first 5900 $v_skip = 0; 5901 for ($i=sizeof($v_list)-1; $i>=0; $i--) { 5902 // ----- Look for current path 5903 if ($v_list[$i] == ".") { 5904 // ----- Ignore this directory 5905 // Should be the first $i=0, but no check is done 5906 } 5907 else if ($v_list[$i] == "..") { 5907 5908 $v_skip++; 5908 }5909 else if ($v_list[$i] == "") {5909 } 5910 else if ($v_list[$i] == "") { 5910 5911 // ----- First '/' i.e. root slash 5911 5912 if ($i == 0) { 5912 $v_result = "/".$v_result;5913 if ($v_skip > 0) {5914 // ----- It is an invalid path, so the path is not modified5915 // TBC5916 $v_result = $p_dir;5917 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid path is unchanged");5918 $v_skip = 0;5919 }5913 $v_result = "/".$v_result; 5914 if ($v_skip > 0) { 5915 // ----- It is an invalid path, so the path is not modified 5916 // TBC 5917 $v_result = $p_dir; 5918 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid path is unchanged"); 5919 $v_skip = 0; 5920 } 5920 5921 } 5921 5922 // ----- Last '/' i.e. indicates a directory 5922 5923 else if ($i == (sizeof($v_list)-1)) { 5923 $v_result = $v_list[$i];5924 $v_result = $v_list[$i]; 5924 5925 } 5925 5926 // ----- Double '/' inside the path 5926 5927 else { 5927 // ----- Ignore only the double '//' in path,5928 // but not the first and last '/'5928 // ----- Ignore only the double '//' in path, 5929 // but not the first and last '/' 5929 5930 } 5930 }5931 else {5931 } 5932 else { 5932 5933 // ----- Look for item to skip 5933 5934 if ($v_skip > 0) { 5934 $v_skip--;5935 $v_skip--; 5935 5936 } 5936 5937 else { 5937 $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");5938 $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); 5938 5939 } 5939 }5940 }5941 5942 // ----- Look for skip5943 if ($v_skip > 0) {5944 while ($v_skip > 0) {5945 $v_result = '../'.$v_result;5946 $v_skip--;5947 }5948 }5949 }5950 5951 // ----- Return5952 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);5953 return $v_result;5940 } 5941 } 5942 5943 // ----- Look for skip 5944 if ($v_skip > 0) { 5945 while ($v_skip > 0) { 5946 $v_result = '../'.$v_result; 5947 $v_skip--; 5948 } 5949 } 5950 } 5951 5952 // ----- Return 5953 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5954 return $v_result; 5954 5955 } 5955 5956 // -------------------------------------------------------------------------------- … … 5972 5973 function PclZipUtilPathInclusion($p_dir, $p_path) 5973 5974 { 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 separator5990 $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 paths5996 $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 items6012 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 items6018 $i++;6019 $j++;6020 }6021 6022 // ----- Look if everything seems to be the same6023 if ($v_result) {6024 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Look for tie break");6025 // ----- Skip all the empty items6026 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 same6032 $v_result = 2;6033 }6034 else if ($i < $v_list_dir_size) {6035 // ----- The path is shorter than the dir6036 $v_result = 0;6037 }6038 }6039 6040 // ----- Return6041 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);6042 return $v_result;5975 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathInclusion", "dir='$p_dir', path='$p_path'"); 5976 $v_result = 1; 5977 5978 // ----- Look for path beginning by ./ 5979 if ( ($p_dir == '.') 5980 || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { 5981 $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); 5982 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_dir '".$p_dir."'"); 5983 } 5984 if ( ($p_path == '.') 5985 || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { 5986 $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); 5987 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_path '".$p_path."'"); 5988 } 5989 5990 // ----- Explode dir and path by directory separator 5991 $v_list_dir = explode("/", $p_dir); 5992 $v_list_dir_size = sizeof($v_list_dir); 5993 $v_list_path = explode("/", $p_path); 5994 $v_list_path_size = sizeof($v_list_path); 5995 5996 // ----- Study directories paths 5997 $i = 0; 5998 $j = 0; 5999 while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) { 6000 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Working on dir($i)='".$v_list_dir[$i]."' and path($j)='".$v_list_path[$j]."'"); 6001 6002 // ----- Look for empty dir (path reduction) 6003 if ($v_list_dir[$i] == '') { 6004 $i++; 6005 continue; 6006 } 6007 if ($v_list_path[$j] == '') { 6008 $j++; 6009 continue; 6010 } 6011 6012 // ----- Compare the items 6013 if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { 6014 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Items ($i,$j) are different"); 6015 $v_result = 0; 6016 } 6017 6018 // ----- Next items 6019 $i++; 6020 $j++; 6021 } 6022 6023 // ----- Look if everything seems to be the same 6024 if ($v_result) { 6025 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Look for tie break"); 6026 // ----- Skip all the empty items 6027 while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; 6028 while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; 6029 //--(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]:'')."'"); 6030 6031 if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { 6032 // ----- There are exactly the same 6033 $v_result = 2; 6034 } 6035 else if ($i < $v_list_dir_size) { 6036 // ----- The path is shorter than the dir 6037 $v_result = 0; 6038 } 6039 } 6040 6041 // ----- Return 6042 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 6043 return $v_result; 6043 6044 } 6044 6045 // -------------------------------------------------------------------------------- … … 6049 6050 // Parameters : 6050 6051 // $p_mode : read/write compression mode 6051 // 0 : src & dest normal6052 // 1 : src gzip, dest normal6053 // 2 : src normal, dest gzip6054 // 3 : src & dest gzip6052 // 0 : src & dest normal 6053 // 1 : src gzip, dest normal 6054 // 2 : src normal, dest gzip 6055 // 3 : src & dest gzip 6055 6056 // Return Values : 6056 6057 // -------------------------------------------------------------------------------- 6057 6058 function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) 6058 6059 { 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 // ----- Return6112 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);6113 return $v_result;6060 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilCopyBlock", "size=$p_size, mode=$p_mode"); 6061 $v_result = 1; 6062 6063 if ($p_mode==0) 6064 { 6065 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset before read :".(@ftell($p_src))); 6066 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset before write :".(@ftell($p_dest))); 6067 while ($p_size != 0) 6068 { 6069 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 6070 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 6071 $v_buffer = @fread($p_src, $v_read_size); 6072 @fwrite($p_dest, $v_buffer, $v_read_size); 6073 $p_size -= $v_read_size; 6074 } 6075 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset after read :".(@ftell($p_src))); 6076 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset after write :".(@ftell($p_dest))); 6077 } 6078 else if ($p_mode==1) 6079 { 6080 while ($p_size != 0) 6081 { 6082 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 6083 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 6084 $v_buffer = @gzread($p_src, $v_read_size); 6085 @fwrite($p_dest, $v_buffer, $v_read_size); 6086 $p_size -= $v_read_size; 6087 } 6088 } 6089 else if ($p_mode==2) 6090 { 6091 while ($p_size != 0) 6092 { 6093 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 6094 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 6095 $v_buffer = @fread($p_src, $v_read_size); 6096 @gzwrite($p_dest, $v_buffer, $v_read_size); 6097 $p_size -= $v_read_size; 6098 } 6099 } 6100 else if ($p_mode==3) 6101 { 6102 while ($p_size != 0) 6103 { 6104 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); 6105 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); 6106 $v_buffer = @gzread($p_src, $v_read_size); 6107 @gzwrite($p_dest, $v_buffer, $v_read_size); 6108 $p_size -= $v_read_size; 6109 } 6110 } 6111 6112 // ----- Return 6113 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 6114 return $v_result; 6114 6115 } 6115 6116 // -------------------------------------------------------------------------------- … … 6129 6130 function PclZipUtilRename($p_src, $p_dest) 6130 6131 { 6131 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilRename", "source=$p_src, destination=$p_dest");6132 $v_result = 1;6133 6134 // ----- Try to rename the files6135 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 src6139 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 // ----- Return6150 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);6151 return $v_result;6132 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilRename", "source=$p_src, destination=$p_dest"); 6133 $v_result = 1; 6134 6135 // ----- Try to rename the files 6136 if (!@rename($p_src, $p_dest)) { 6137 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to rename file, try copy+unlink"); 6138 6139 // ----- Try to copy & unlink the src 6140 if (!@copy($p_src, $p_dest)) { 6141 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to copy file"); 6142 $v_result = 0; 6143 } 6144 else if (!@unlink($p_src)) { 6145 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to unlink old filename"); 6146 $v_result = 0; 6147 } 6148 } 6149 6150 // ----- Return 6151 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 6152 return $v_result; 6152 6153 } 6153 6154 // -------------------------------------------------------------------------------- … … 6164 6165 function PclZipUtilOptionText($p_option) 6165 6166 { 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)) {6167 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilOptionText", "option='".$p_option."'"); 6168 6169 $v_list = get_defined_constants(); 6170 for (reset($v_list); $v_key = key($v_list); next($v_list)) { 6170 6171 $v_prefix = substr($v_key, 0, 10); 6171 6172 if (( ($v_prefix == 'PCLZIP_OPT') 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;6173 || ($v_prefix == 'PCLZIP_CB_') 6174 || ($v_prefix == 'PCLZIP_ATT')) 6175 && ($v_list[$v_key] == $p_option)) { 6176 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_key); 6177 return $v_key; 6178 } 6179 } 6180 6181 $v_result = 'Unknown'; 6182 6183 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 6184 return $v_result; 6184 6185 } 6185 6186 // -------------------------------------------------------------------------------- … … 6198 6199 function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true) 6199 6200 { 6200 if (stristr(php_uname(), 'windows')) {6201 // ----- Look for potential disk letter6202 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 separator6206 if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {6207 $p_path = strtr($p_path, '\\', '/');6208 }6209 }6210 return $p_path;6201 if (stristr(php_uname(), 'windows')) { 6202 // ----- Look for potential disk letter 6203 if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { 6204 $p_path = substr($p_path, $v_position+1); 6205 } 6206 // ----- Change potential windows directory separator 6207 if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { 6208 $p_path = strtr($p_path, '\\', '/'); 6209 } 6210 } 6211 return $p_path; 6211 6212 } 6212 6213 // --------------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.