Ticket #9464: pclzip.update.patch
| File pclzip.update.patch, 71.0 KB (added by , 17 years ago) |
|---|
-
wp-admin/includes/class-pclzip.php
1 1 <?php 2 /** 3 * PhpConcept Library - Zip Module 2.5 4 * 5 * Presentation : 6 * PclZip is a PHP library that manage ZIP archives. 7 * So far tests show that archives generated by PclZip are readable by 8 * WinZip application and other tools. 9 * 10 * Warning : 11 * This library and the associated files are non commercial, non professional 12 * work. 13 * It should not have unexpected results. However if any damage is caused by 14 * this software the author can not be responsible. 15 * The use of this software is at the risk of the user. 16 * 17 * @package External 18 * @subpackage PclZip 19 * 20 * @license License GNU/LGPL 21 * @copyright March 2006 Vincent Blavet 22 * @author Vincent Blavet 23 * @link http://www.phpconcept.net 24 * @version $Id: pclzip.lib.php,v 1.44 2006/03/08 21:23:59 vblavet Exp $ 25 */ 2 // -------------------------------------------------------------------------------- 3 // PhpConcept Library - Zip Module 2.7 4 // -------------------------------------------------------------------------------- 5 // License GNU/LGPL - Vincent Blavet - March 2006 6 // http://www.phpconcept.net 7 // -------------------------------------------------------------------------------- 8 // 9 // Presentation : 10 // PclZip is a PHP library that manage ZIP archives. 11 // So far tests show that archives generated by PclZip are readable by 12 // WinZip application and other tools. 13 // 14 // Description : 15 // See readme.txt and http://www.phpconcept.net 16 // 17 // Warning : 18 // This library and the associated files are non commercial, non professional 19 // work. 20 // It should not have unexpected results. However if any damage is caused by 21 // this software the author can not be responsible. 22 // The use of this software is at the risk of the user. 23 // 24 // -------------------------------------------------------------------------------- 25 // $Id: pclzip.lib.php,v 1.50 2009/03/24 17:13:52 vblavet Exp $ 26 // -------------------------------------------------------------------------------- 26 27 27 /** 28 * The read block size for reading zip files. 29 * 30 * @since 2.5 31 */ 32 define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); 28 // ----- Constants 29 if (!defined('PCLZIP_READ_BLOCK_SIZE')) { 30 define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); 31 } 32 33 // ----- File list separator 34 // In version 1.x of PclZip, the separator for file list is a space 35 // (which is not a very smart choice, specifically for windows paths !). 36 // A better separator should be a comma (,). This constant gives you the 37 // abilty to change that. 38 // However notice that changing this value, may have impact on existing 39 // scripts, using space separated filenames. 40 // Recommanded values for compatibility with older versions : 41 //define( 'PCLZIP_SEPARATOR', ' ' ); 42 // Recommanded values for smart separation of filenames. 43 if (!defined('PCLZIP_SEPARATOR')) { 44 define( 'PCLZIP_SEPARATOR', ',' ); 45 } 33 46 34 /** 35 * File list separator 36 * 37 * In version 1.x of PclZip, the separator for file list is a space(which is not 38 * a very smart choice, specifically for windows paths !). A better separator 39 * should be a comma (,). This constant gives you the abilty to change that. 40 * 41 * However notice that changing this value, may have impact on existing scripts, 42 * using space separated filenames. Recommanded values for compatibility with 43 * older versions : 44 * <code>define( 'PCLZIP_SEPARATOR', ' ' );</code> 45 * Recommanded values for smart separation of filenames. 46 */ 47 define( 'PCLZIP_SEPARATOR', ',' ); 47 // ----- Error configuration 48 // 0 : PclZip Class integrated error handling 49 // 1 : PclError external library error handling. By enabling this 50 // you must ensure that you have included PclError library. 51 // [2,...] : reserved for futur use 52 if (!defined('PCLZIP_ERROR_EXTERNAL')) { 53 define( 'PCLZIP_ERROR_EXTERNAL', 0 ); 54 } 48 55 49 /**50 * Error configuration51 *52 * 0 : PclZip Class integrated error handling53 * 1 : PclError external library error handling. By enabling this you must54 * ensure that you have included PclError library.55 * [2,...] : reserved for future use56 */57 define( 'PCLZIP_ERROR_EXTERNAL', 0 );58 59 56 // ----- Optional static temporary directory 60 57 // By default temporary files are generated in the script current 61 58 // path. … … 65 62 // Samples : 66 63 // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' ); 67 64 // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' ); 68 define( 'PCLZIP_TEMPORARY_DIR', '' ); 65 if (!defined('PCLZIP_TEMPORARY_DIR')) { 66 define( 'PCLZIP_TEMPORARY_DIR', '' ); 67 } 69 68 70 69 // -------------------------------------------------------------------------------- 71 70 // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED ***** 72 71 // -------------------------------------------------------------------------------- 73 72 74 73 // ----- Global variables 75 $g_pclzip_version = "2. 5";74 $g_pclzip_version = "2.7"; 76 75 77 76 // ----- Error codes 78 77 // -1 : Unable to open file in binary write mode … … 135 134 // which is not correctly supported by PHP ... 136 135 //define( 'PCLZIP_OPT_CRYPT', 77018 ); 137 136 define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); 138 137 define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); 138 define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); 139 define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); 140 139 141 // ----- File description attributes 140 142 define( 'PCLZIP_ATT_FILE_NAME', 79001 ); 141 143 define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 ); 142 144 define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 ); 145 define( 'PCLZIP_ATT_FILE_MTIME', 79004 ); 146 define( 'PCLZIP_ATT_FILE_CONTENT', 79005 ); 147 define( 'PCLZIP_ATT_FILE_COMMENT', 79006 ); 143 148 144 149 // ----- Call backs values 145 150 define( 'PCLZIP_CB_PRE_EXTRACT', 78001 ); 146 151 define( 'PCLZIP_CB_POST_EXTRACT', 78002 ); 147 152 define( 'PCLZIP_CB_PRE_ADD', 78003 ); 148 153 define( 'PCLZIP_CB_POST_ADD', 78004 ); 149 /* For futur euse154 /* For futur use 150 155 define( 'PCLZIP_CB_PRE_LIST', 78005 ); 151 156 define( 'PCLZIP_CB_POST_LIST', 78006 ); 152 157 define( 'PCLZIP_CB_PRE_DELETE', 78007 ); … … 178 183 // ----- Internal error handling 179 184 var $error_code = 1; 180 185 var $error_string = ''; 181 186 182 187 // ----- Current status of the magic_quotes_runtime 183 188 // This value store the php configuration for magic_quotes 184 189 // The class can then disable the magic_quotes and reset it after … … 288 293 PCLZIP_CB_PRE_ADD => 'optional', 289 294 PCLZIP_CB_POST_ADD => 'optional', 290 295 PCLZIP_OPT_NO_COMPRESSION => 'optional', 291 PCLZIP_OPT_COMMENT => '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' 292 300 //, PCLZIP_OPT_CRYPT => 'optional' 293 301 )); 294 302 if ($v_result != 1) { … … 318 326 } 319 327 } 320 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 } 321 334 322 335 // ----- Init 323 336 $v_string_list = array(); 324 337 $v_att_list = array(); 325 338 $v_filedescr_list = array(); 326 339 $p_result_list = array(); 327 340 328 341 // ----- Look if the $p_filelist is really an array 329 342 if (is_array($p_filelist)) { 330 343 331 344 // ----- Look if the first element is also an array 332 345 // This will mean that this is a file description entry 333 346 if (isset($p_filelist[0]) && is_array($p_filelist[0])) { 334 347 $v_att_list = $p_filelist; 335 348 } 336 349 337 350 // ----- The list is a list of string names 338 351 else { 339 352 $v_string_list = $p_filelist; … … 352 365 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 353 366 return 0; 354 367 } 355 368 356 369 // ----- Reformat the string list 357 370 if (sizeof($v_string_list) != 0) { 358 371 foreach ($v_string_list as $v_string) { … … 364 377 } 365 378 } 366 379 } 367 380 368 381 // ----- For each file in the list check the attributes 369 382 $v_supported_attributes 370 383 = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' 371 384 ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' 372 385 ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' 386 ,PCLZIP_ATT_FILE_MTIME => 'optional' 387 ,PCLZIP_ATT_FILE_CONTENT => 'optional' 388 ,PCLZIP_ATT_FILE_COMMENT => 'optional' 373 389 ); 374 390 foreach ($v_att_list as $v_entry) { 375 391 $v_result = $this->privFileDescrParseAtt($v_entry, … … 476 492 PCLZIP_OPT_NO_COMPRESSION => 'optional', 477 493 PCLZIP_OPT_COMMENT => 'optional', 478 494 PCLZIP_OPT_ADD_COMMENT => 'optional', 479 PCLZIP_OPT_PREPEND_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' 480 499 //, PCLZIP_OPT_CRYPT => 'optional' 481 500 )); 482 501 if ($v_result != 1) { … … 509 528 } 510 529 } 511 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 512 536 // ----- Init 513 537 $v_string_list = array(); 514 538 $v_att_list = array(); 515 539 $v_filedescr_list = array(); 516 540 $p_result_list = array(); 517 541 518 542 // ----- Look if the $p_filelist is really an array 519 543 if (is_array($p_filelist)) { 520 544 521 545 // ----- Look if the first element is also an array 522 546 // This will mean that this is a file description entry 523 547 if (isset($p_filelist[0]) && is_array($p_filelist[0])) { 524 548 $v_att_list = $p_filelist; 525 549 } 526 550 527 551 // ----- The list is a list of string names 528 552 else { 529 553 $v_string_list = $p_filelist; … … 542 566 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); 543 567 return 0; 544 568 } 545 569 546 570 // ----- Reformat the string list 547 571 if (sizeof($v_string_list) != 0) { 548 572 foreach ($v_string_list as $v_string) { 549 573 $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; 550 574 } 551 575 } 552 576 553 577 // ----- For each file in the list check the attributes 554 578 $v_supported_attributes 555 579 = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' 556 580 ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' 557 581 ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' 582 ,PCLZIP_ATT_FILE_MTIME => 'optional' 583 ,PCLZIP_ATT_FILE_CONTENT => 'optional' 584 ,PCLZIP_ATT_FILE_COMMENT => 'optional' 558 585 ); 559 586 foreach ($v_att_list as $v_entry) { 560 587 $v_result = $this->privFileDescrParseAtt($v_entry, … … 615 642 // write protected 616 643 // newer_exist : the file was not extracted because a newer file exists 617 644 // path_creation_fail : the file is not extracted because the folder 618 // does not exist sand can not be created645 // does not exist and can not be created 619 646 // write_error : the file was not extracted because there was a 620 647 // error while writing the file 621 648 // read_error : the file was not extracted because there was a error … … 999 1026 // Options : 1000 1027 // PCLZIP_OPT_BY_INDEX : 1001 1028 // PCLZIP_OPT_BY_NAME : 1002 // PCLZIP_OPT_BY_EREG : 1029 // PCLZIP_OPT_BY_EREG : 1003 1030 // PCLZIP_OPT_BY_PREG : 1004 1031 // Return Values : 1005 1032 // 0 on failure, … … 1074 1101 function deleteByIndex($p_index) 1075 1102 { 1076 1103 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'"); 1077 1104 1078 1105 $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); 1079 1106 1080 1107 // ----- Return … … 1128 1155 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) 1129 1156 { 1130 1157 $this->privSwapBackMagicQuotes(); 1131 1158 1132 1159 // ----- Error log 1133 1160 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); 1134 1161 … … 1457 1484 { 1458 1485 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", ""); 1459 1486 $v_result=1; 1460 1487 1461 1488 // ----- Read the options 1462 1489 $i=0; 1463 1490 while ($i<$p_size) { … … 1490 1517 } 1491 1518 1492 1519 // ----- Get the value 1493 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);1520 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); 1494 1521 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1495 1522 $i++; 1496 1523 break; 1497 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 1498 1584 case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : 1499 1585 // ----- Check the number of parameters 1500 1586 if (($i+1) >= $p_size) { … … 1509 1595 // ----- Get the value 1510 1596 if ( is_string($p_options_list[$i+1]) 1511 1597 && ($p_options_list[$i+1] != '')) { 1512 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);1598 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); 1513 1599 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); 1514 1600 $i++; 1515 1601 } … … 1654 1740 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1655 1741 return PclZip::errorCode(); 1656 1742 } 1657 1743 1658 1744 // ----- Reduce the index list 1659 1745 // each index item in the list must be a couple with a start and 1660 1746 // an end value : [0,3], [5-5], [8-10], ... … … 1665 1751 // ----- Explode the item 1666 1752 $v_item_list = explode("-", $v_work_list[$j]); 1667 1753 $v_size_item_list = sizeof($v_item_list); 1668 1754 1669 1755 // ----- TBC : Here we might check that each item is a 1670 1756 // real integer ... 1671 1757 1672 1758 // ----- Look for single value 1673 1759 if ($v_size_item_list == 1) { 1674 1760 // ----- Set the option value … … 1706 1792 } 1707 1793 $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; 1708 1794 } 1709 1795 1710 1796 // ----- Sort the items 1711 1797 if ($v_sort_flag) { 1712 1798 // TBC : To Be Completed … … 1819 1905 } 1820 1906 } 1821 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 } 1822 1914 1823 1915 // ----- Return 1824 1916 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); … … 1827 1919 // -------------------------------------------------------------------------------- 1828 1920 1829 1921 // -------------------------------------------------------------------------------- 1922 // Function : privOptionDefaultThreshold() 1923 // Description : 1924 // Parameters : 1925 // Return Values : 1926 // -------------------------------------------------------------------------------- 1927 function privOptionDefaultThreshold(&$p_options) 1928 { 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)); 1937 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; 1960 } 1961 // -------------------------------------------------------------------------------- 1962 1963 // -------------------------------------------------------------------------------- 1830 1964 // Function : privFileDescrParseAtt() 1831 1965 // Description : 1832 1966 // Parameters : … … 1838 1972 { 1839 1973 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", ""); 1840 1974 $v_result=1; 1841 1975 1842 1976 // ----- For each file in the list check the attributes 1843 1977 foreach ($p_file_list as $v_key => $v_value) { 1844 1978 1845 1979 // ----- Check if the option is supported 1846 1980 if (!isset($v_requested_options[$v_key])) { 1847 1981 // ----- Error log … … 1863 1997 1864 1998 $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); 1865 1999 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 1866 2000 1867 2001 if ($p_filedescr['filename'] == '') { 1868 2002 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); 1869 2003 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); … … 1906 2040 } 1907 2041 break; 1908 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 1909 2071 default : 1910 2072 // ----- Error log 1911 2073 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, … … 1931 2093 } 1932 2094 } 1933 2095 } 1934 2096 1935 2097 // end foreach 1936 2098 } 1937 2099 1938 2100 // ----- Return 1939 2101 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 1940 2102 return $v_result; … … 1944 2106 // -------------------------------------------------------------------------------- 1945 2107 // Function : privFileDescrExpand() 1946 2108 // Description : 2109 // This method look for each item of the list to see if its a file, a folder 2110 // or a string to be added as file. For any other type of files (link, other) 2111 // just ignore the item. 2112 // Then prepare the information that will be stored for that file. 2113 // When its a folder, expand the folder with all the files that are in that 2114 // folder (recursively). 1947 2115 // Parameters : 1948 2116 // Return Values : 1949 2117 // 1 on success. … … 1953 2121 { 1954 2122 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", ""); 1955 2123 $v_result=1; 1956 2124 1957 2125 // ----- Create a result list 1958 2126 $v_result_list = array(); 1959 2127 1960 2128 // ----- Look each entry 1961 2129 for ($i=0; $i<sizeof($p_filedescr_list); $i++) { 2130 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for file ".$i."."); 2131 1962 2132 // ----- Get filedescr 1963 2133 $v_descr = $p_filedescr_list[$i]; 1964 2134 1965 2135 // ----- Reduce the filename 1966 2136 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'"); 1967 $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'] );2137 $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); 1968 2138 $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); 1969 2139 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'"); 1970 1971 // ----- Get type of descr 1972 if (!file_exists($v_descr['filename'])) { 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 { 1973 2171 // ----- Error log 1974 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exist s");1975 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist s");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"); 1976 2174 1977 2175 // ----- Return 1978 2176 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 1979 2177 return PclZip::errorCode(); 1980 2178 } 1981 if (@is_file($v_descr['filename'])) { 1982 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file"); 1983 $v_descr['type'] = 'file'; 1984 } 1985 else if (@is_dir($v_descr['filename'])) { 1986 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder"); 1987 $v_descr['type'] = 'folder'; 1988 } 1989 else if (@is_link($v_descr['filename'])) { 1990 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link"); 1991 // skip 1992 continue; 1993 } 1994 else { 1995 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type"); 1996 // skip 1997 continue; 1998 } 1999 2179 2000 2180 // ----- Calculate the stored filename 2001 2181 $this->privCalculateStoredFilename($v_descr, $p_options); 2002 2182 2003 2183 // ----- Add the descriptor in result list 2004 2184 $v_result_list[sizeof($v_result_list)] = $v_descr; 2005 2185 2006 2186 // ----- Look for folder 2007 2187 if ($v_descr['type'] == 'folder') { 2008 2188 // ----- List of items in folder … … 2016 2196 if (($v_item_handler == '.') || ($v_item_handler == '..')) { 2017 2197 continue; 2018 2198 } 2019 2199 2020 2200 // ----- Compose the full filename 2021 2201 $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; 2022 2202 2023 2203 // ----- Look for different stored filename 2024 2204 // Because the name of the folder was changed, the name of the 2025 2205 // files/sub-folders also change 2026 2206 if ($v_descr['stored_filename'] != $v_descr['filename']) { 2027 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; 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 } 2028 2213 } 2029 2214 2030 2215 $v_dirlist_nb++; 2031 2216 } 2217 2218 @closedir($v_folder_handler); 2032 2219 } 2033 2220 else { 2034 2221 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped."); 2035 2222 // TBC : unable to open folder in read mode 2036 2223 } 2037 2224 2038 2225 // ----- Expand each element of the list 2039 2226 if ($v_dirlist_nb != 0) { 2040 2227 // ----- Expand … … 2042 2229 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2043 2230 return $v_result; 2044 2231 } 2045 2232 2046 2233 // ----- Concat the resulting list 2047 2234 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')"); 2048 2235 $v_result_list = array_merge($v_result_list, $v_dirlist_descr); … … 2051 2238 else { 2052 2239 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand."); 2053 2240 } 2054 2241 2055 2242 // ----- Free local array 2056 2243 unset($v_dirlist_descr); 2057 2244 } 2058 2245 } 2059 2246 2060 2247 // ----- Get the result list 2061 2248 $p_filedescr_list = $v_result_list; 2062 2249 … … 2077 2264 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list"); 2078 2265 $v_result=1; 2079 2266 $v_list_detail = array(); 2080 2267 2081 2268 // ----- Magic quotes trick 2082 2269 $this->privDisableMagicQuotes(); 2083 2270 … … 2438 2625 // Function : privAddFileList() 2439 2626 // Description : 2440 2627 // Parameters : 2441 // $p_filedescr_list : An array containing the file description 2628 // $p_filedescr_list : An array containing the file description 2442 2629 // or directory names to add in the zip 2443 2630 // $p_result_list : list of added files with their properties (specially the status field) 2444 2631 // Return Values : … … 2458 2645 // ----- Format the filename 2459 2646 $p_filedescr_list[$j]['filename'] 2460 2647 = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); 2461 2648 2462 2649 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'"); 2463 2650 2464 2651 // ----- Skip empty file names … … 2469 2656 } 2470 2657 2471 2658 // ----- Check the filename 2472 if (!file_exists($p_filedescr_list[$j]['filename'])) { 2473 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_filedescr_list[$j]['filename']."' does not exists"); 2474 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exists"); 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"); 2475 2663 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2476 2664 return PclZip::errorCode(); 2477 2665 } 2478 2666 2479 2667 // ----- Look if it is a file or a dir with no all path remove option 2480 if ( (is_file($p_filedescr_list[$j]['filename'])) 2481 || ( is_dir($p_filedescr_list[$j]['filename']) 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') 2482 2674 && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) 2483 || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { 2675 || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) 2676 ) { 2484 2677 2485 2678 // ----- Add the file 2486 2679 $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header, … … 2512 2705 { 2513 2706 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'"); 2514 2707 $v_result=1; 2515 2708 2516 2709 // ----- Working variable 2517 2710 $p_filename = $p_filedescr['filename']; 2518 2711 … … 2525 2718 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 2526 2719 return PclZip::errorCode(); 2527 2720 } 2528 2529 // ----- Look for a stored different filename 2721 2722 // ----- Look for a stored different filename 2723 /* TBC : Removed 2530 2724 if (isset($p_filedescr['stored_filename'])) { 2531 2725 $v_stored_filename = $p_filedescr['stored_filename']; 2532 2726 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is NOT the same "'.$v_stored_filename.'"'); … … 2535 2729 $v_stored_filename = $p_filedescr['stored_filename']; 2536 2730 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is the same'); 2537 2731 } 2732 */ 2538 2733 2539 2734 // ----- Set the file properties 2540 2735 clearstatcache(); … … 2542 2737 $p_header['version_extracted'] = 10; 2543 2738 $p_header['flag'] = 0; 2544 2739 $p_header['compression'] = 0; 2545 $p_header['mtime'] = filemtime($p_filename);2546 2740 $p_header['crc'] = 0; 2547 2741 $p_header['compressed_size'] = 0; 2548 $p_header['size'] = filesize($p_filename);2549 2742 $p_header['filename_len'] = strlen($p_filename); 2550 2743 $p_header['extra_len'] = 0; 2551 $p_header['comment_len'] = 0;2552 2744 $p_header['disk'] = 0; 2553 2745 $p_header['internal'] = 0; 2554 // $p_header['external'] = (is_file($p_filename)?0xFE49FFE0:0x41FF0010);2555 $p_header['external'] = (is_file($p_filename)?0x00000000:0x00000010);2556 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header external extension '".sprintf("0x%X",$p_header['external'])."'");2557 2746 $p_header['offset'] = 0; 2558 2747 $p_header['filename'] = $p_filename; 2559 $p_header['stored_filename'] = $v_stored_filename; 2748 // TBC : Removed $p_header['stored_filename'] = $v_stored_filename; 2749 $p_header['stored_filename'] = $p_filedescr['stored_filename']; 2560 2750 $p_header['extra'] = ''; 2561 $p_header['comment'] = '';2562 2751 $p_header['status'] = 'ok'; 2563 2752 $p_header['index'] = -1; 2564 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 2565 2796 // ----- Look for pre-add callback 2566 2797 if (isset($p_options[PCLZIP_CB_PRE_ADD])) { 2567 2798 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_ADD]."()') is defined for the extraction"); … … 2592 2823 if ($p_header['stored_filename'] == "") { 2593 2824 $p_header['status'] = "filtered"; 2594 2825 } 2595 2826 2596 2827 // ----- Check the path length 2597 2828 if (strlen($p_header['stored_filename']) > 0xFF) { 2598 2829 $p_header['status'] = 'filename_too_long'; … … 2602 2833 if ($p_header['status'] == 'ok') { 2603 2834 2604 2835 // ----- Look for a file 2605 if (is_file($p_filename)) 2606 { 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 2607 2851 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file"); 2852 2608 2853 // ----- Open the source file 2609 2854 if (($v_file = @fopen($p_filename, "rb")) == 0) { 2610 2855 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); … … 2612 2857 return PclZip::errorCode(); 2613 2858 } 2614 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 2615 2870 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { 2616 2871 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed"); 2617 // ----- Read the file content2618 $v_content_compressed = @fread($v_file, $p_header['size']);2619 2620 // ----- Calculate the CRC2621 $p_header['crc'] = @crc32($v_content_compressed);2622 2623 2872 // ----- Set header parameters 2624 2873 $p_header['compressed_size'] = $p_header['size']; 2625 2874 $p_header['compression'] = 0; 2626 2875 } 2876 2877 // ----- Look for normal compression 2627 2878 else { 2628 2879 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed"); 2629 // ----- Read the file content2630 $v_content = @ fread($v_file, $p_header['size']);2880 // ----- Compress the content 2881 $v_content = @gzdeflate($v_content); 2631 2882 2632 // ----- Calculate the CRC 2633 $p_header['crc'] = @crc32($v_content); 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, 2899 $p_header['crc'], 2900 "test"); 2901 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 */ 2634 2910 2635 // ----- Compress the file 2636 $v_content_compressed = @gzdeflate($v_content); 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 } 2637 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"); 2638 2937 // ----- Set header parameters 2639 $p_header['compressed_size'] = strlen($v_content_compressed); 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); 2640 2950 $p_header['compression'] = 8; 2641 2951 } 2642 2952 2643 2953 // ----- Look for encryption 2644 2954 /* 2645 2955 if ((isset($p_options[PCLZIP_OPT_CRYPT])) 2646 2956 && ($p_options[PCLZIP_OPT_CRYPT] != "")) { 2647 2957 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ...."); 2648 2958 2649 2959 // Should be a random header 2650 2960 $v_header = 'xxxxxxxxxxxx'; 2651 2961 $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed, … … 2653 2963 $v_header, 2654 2964 $p_header['crc'], 2655 2965 "test"); 2656 2966 2657 2967 $p_header['compressed_size'] += 12; 2658 2968 $p_header['flag'] = 1; 2659 2969 2660 2970 // ----- Add the header to the data 2661 2971 $v_content_compressed = $v_header.$v_content_compressed; 2662 2972 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed).""); … … 2671 2981 } 2672 2982 2673 2983 // ----- Write the compressed (or not) content 2674 @fwrite($this->zip_fd, 2675 $v_content_compressed, $p_header['compressed_size']); 2676 2677 // ----- Close the file 2678 @fclose($v_file); 2984 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); 2679 2985 } 2680 2986 2681 2987 // ----- Look for a directory 2682 else {2988 else if ($p_filedescr['type'] == 'folder') { 2683 2989 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder"); 2684 2990 // ----- Look for directory last '/' 2685 2991 if (@substr($p_header['stored_filename'], -1) != '/') { … … 2728 3034 // -------------------------------------------------------------------------------- 2729 3035 2730 3036 // -------------------------------------------------------------------------------- 3037 // Function : privAddFileUsingTempFile() 3038 // Description : 3039 // Parameters : 3040 // Return Values : 3041 // -------------------------------------------------------------------------------- 3042 function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) 3043 { 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; 3168 } 3169 // -------------------------------------------------------------------------------- 3170 3171 // -------------------------------------------------------------------------------- 2731 3172 // Function : privCalculateStoredFilename() 2732 3173 // Description : 2733 3174 // Based on file descriptor properties and global options, this method … … 2739 3180 { 2740 3181 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCalculateStoredFilename", "filename='".$p_filedescr['filename']."'"); 2741 3182 $v_result=1; 2742 3183 2743 3184 // ----- Working variables 2744 3185 $p_filename = $p_filedescr['filename']; 2745 3186 if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { … … 2754 3195 else { 2755 3196 $p_remove_dir = ''; 2756 3197 } 3198 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Remove path ='".$p_remove_dir."'"); 2757 3199 if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { 2758 3200 $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; 2759 3201 } … … 2763 3205 2764 3206 // ----- Look for full name change 2765 3207 if (isset($p_filedescr['new_full_name'])) { 2766 $v_stored_filename = $p_filedescr['new_full_name']; 3208 // ----- Remove drive letter if any 3209 $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']); 2767 3210 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing full name of '".$p_filename."' for '".$v_stored_filename."'"); 2768 3211 } 2769 3212 2770 3213 // ----- Look for path and/or short name change 2771 3214 else { 2772 3215 2773 3216 // ----- Look for short name change 3217 // Its when we cahnge just the filename but not the path 2774 3218 if (isset($p_filedescr['new_short_name'])) { 2775 3219 $v_path_info = pathinfo($p_filename); 2776 3220 $v_dir = ''; … … 2792 3236 } 2793 3237 // ----- Look for partial path remove 2794 3238 else if ($p_remove_dir != "") { 3239 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Partial path to remove"); 2795 3240 if (substr($p_remove_dir, -1) != '/') 2796 3241 $p_remove_dir .= "/"; 2797 3242 2798 3243 if ( (substr($p_filename, 0, 2) == "./") 2799 3244 || (substr($p_remove_dir, 0, 2) == "./")) { 2800 3245 2801 3246 if ( (substr($p_filename, 0, 2) == "./") 2802 3247 && (substr($p_remove_dir, 0, 2) != "./")) { 2803 3248 $p_remove_dir = "./".$p_remove_dir; … … 2823 3268 } 2824 3269 } 2825 3270 } 3271 3272 // ----- Remove drive letter if any 3273 $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename); 3274 2826 3275 // ----- Look for path to add 2827 3276 if ($p_add_dir != "") { 2828 3277 if (substr($p_add_dir, -1) == "/") … … 2837 3286 $v_stored_filename = PclZipUtilPathReduction($v_stored_filename); 2838 3287 $p_filedescr['stored_filename'] = $v_stored_filename; 2839 3288 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Stored filename will be '".$p_filedescr['stored_filename']."', strlen ".strlen($p_filedescr['stored_filename'])); 2840 3289 2841 3290 // ----- Return 2842 3291 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 2843 3292 return $v_result; … … 2915 3364 $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; 2916 3365 $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; 2917 3366 3367 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment size : \''.$p_header['comment_len'].'\''); 3368 2918 3369 // ----- Packed data 2919 3370 $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, 2920 3371 $p_header['version'], $p_header['version_extracted'], … … 3000 3451 { 3001 3452 // ----- Magic quotes trick 3002 3453 $this->privSwapBackMagicQuotes(); 3003 3454 3004 3455 // ----- Error log 3005 3456 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); 3006 3457 … … 3080 3531 // $p_info['comment'] = Comment associated with the file. 3081 3532 // $p_info['folder'] = true/false : indicates if the entry is a folder or not. 3082 3533 // $p_info['status'] = status of the action on the file. 3534 // $p_info['crc'] = CRC of the file content. 3083 3535 // Parameters : 3084 3536 // Return Values : 3085 3537 // -------------------------------------------------------------------------------- … … 3098 3550 $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); 3099 3551 $p_info['index'] = $p_header['index']; 3100 3552 $p_info['status'] = $p_header['status']; 3553 $p_info['crc'] = $p_header['crc']; 3101 3554 3102 3555 // ----- Return 3103 3556 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); … … 3279 3732 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) 3280 3733 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { 3281 3734 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'"); 3282 3735 3283 3736 // ----- Look if the index is in the list 3284 3737 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { 3285 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']."]"); … … 3319 3772 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); 3320 3773 3321 3774 $this->privSwapBackMagicQuotes(); 3322 3775 3323 3776 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, 3324 3777 "Filename '".$v_header['stored_filename']."' is " 3325 3778 ."compressed by an unsupported compression " … … 3329 3782 return PclZip::errorCode(); 3330 3783 } 3331 3784 } 3332 3785 3333 3786 // ----- Check encrypted files 3334 3787 if (($v_extract) && (($v_header['flag'] & 1) == 1)) { 3335 3788 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported file encryption"); … … 3366 3819 3367 3820 $v_extract = false; 3368 3821 } 3369 3822 3370 3823 // ----- Look for real extraction 3371 3824 if ($v_extract) 3372 3825 { … … 3420 3873 3421 3874 // ----- Next extracted file 3422 3875 $v_nb_extracted++; 3423 3876 3424 3877 // ----- Look for user callback abort 3425 3878 if ($v_result1 == 2) { 3426 3879 break; … … 3572 4025 if ($p_path != '') { 3573 4026 $p_entry['filename'] = $p_path."/".$p_entry['filename']; 3574 4027 } 3575 4028 3576 4029 // ----- Check a base_dir_restriction 3577 4030 if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { 3578 4031 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Check the extract directory restriction"); 3579 4032 $v_inclusion 3580 4033 = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], 3581 $p_entry['filename']); 4034 $p_entry['filename']); 3582 4035 if ($v_inclusion == 0) { 3583 4036 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction"); 3584 4037 … … 3608 4061 $p_entry['status'] = "skipped"; 3609 4062 $v_result = 1; 3610 4063 } 3611 4064 3612 4065 // ----- Look for abort result 3613 4066 if ($v_result == 2) { 3614 4067 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); … … 3640 4093 3641 4094 // ----- Change the file status 3642 4095 $p_entry['status'] = "already_a_directory"; 3643 4096 3644 4097 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 3645 4098 // For historical reason first PclZip implementation does not stop 3646 4099 // when this kind of error occurs. … … 3654 4107 3655 4108 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3656 4109 return PclZip::errorCode(); 3657 }4110 } 3658 4111 } 3659 4112 // ----- Look if file is write protected 3660 4113 else if (!is_writeable($p_entry['filename'])) … … 3677 4130 3678 4131 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3679 4132 return PclZip::errorCode(); 3680 }4133 } 3681 4134 } 3682 4135 3683 4136 // ----- Look if the extracted file is older … … 3688 4141 if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) 3689 4142 && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { 3690 4143 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_REPLACE_NEWER is selected, file will be replaced"); 3691 }3692 else {4144 } 4145 else { 3693 4146 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be replaced"); 3694 4147 $p_entry['status'] = "newer_exist"; 3695 4148 … … 3706 4159 3707 4160 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); 3708 4161 return PclZip::errorCode(); 4162 } 3709 4163 } 3710 }3711 4164 } 3712 4165 else { 3713 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']).")"); … … 3723 4176 else 3724 4177 $v_dir_to_check = dirname($p_entry['filename']); 3725 4178 3726 if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { 3727 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '".$p_entry['filename']."'"); 3728 3729 // ----- Change the file status 3730 $p_entry['status'] = "path_creation_fail"; 3731 3732 // ----- Return 3733 ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3734 //return $v_result; 3735 $v_result = 1; 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 } 3736 4190 } 3737 4191 } 3738 }3739 4192 3740 4193 // ----- Look if extraction should be done 3741 4194 if ($p_entry['status'] == 'ok') { … … 3773 4226 $v_binary_data = pack('a'.$v_read_size, $v_buffer); 3774 4227 @fwrite($v_dest_file, $v_binary_data, $v_read_size); 3775 4228 */ 3776 @fwrite($v_dest_file, $v_buffer, $v_read_size); 4229 @fwrite($v_dest_file, $v_buffer, $v_read_size); 3777 4230 $v_size -= $v_read_size; 3778 4231 } 3779 4232 … … 3782 4235 3783 4236 // ----- Change the file mtime 3784 4237 touch($p_entry['filename'], $p_entry['mtime']); 4238 3785 4239 3786 3787 4240 } 3788 4241 else { 3789 4242 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (Compression method ".$p_entry['compression'].")"); … … 3795 4248 // ----- Read the encryption header 3796 4249 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read 12 encryption header bytes"); 3797 4250 $v_encryption_header = @fread($this->zip_fd, 12); 3798 4251 3799 4252 // ----- Read the encrypted & compressed file in a buffer 3800 4253 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".($p_entry['compressed_size']-12)."' compressed & encrypted bytes"); 3801 4254 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']-12); 3802 4255 3803 4256 // ----- Decrypt the buffer 3804 4257 $this->privDecrypt($v_encryption_header, $v_buffer, 3805 4258 $p_entry['compressed_size']-12, $p_entry['crc']); … … 3811 4264 // ----- Read the compressed file in a buffer (one shot) 3812 4265 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 3813 4266 } 3814 4267 3815 4268 // ----- Decompress the file 3816 4269 $v_file_content = @gzinflate($v_buffer); 3817 4270 unset($v_buffer); … … 3821 4274 // ----- Change the file status 3822 4275 // TBC 3823 4276 $p_entry['status'] = "error"; 3824 4277 3825 4278 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3826 4279 return $v_result; 3827 4280 } 3828 4281 3829 4282 // ----- Opening destination file 3830 4283 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { 3831 4284 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); … … 3864 4317 if ($p_entry['status'] == "aborted") { 3865 4318 $p_entry['status'] = "skipped"; 3866 4319 } 3867 4320 3868 4321 // ----- Look for post-extract callback 3869 4322 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { 3870 4323 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction"); … … 3973 4426 3974 4427 // ----- Read the compressed file in a buffer (one shot) 3975 4428 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 3976 4429 3977 4430 // ----- Decompress the file 3978 4431 $v_file_content = gzinflate($v_buffer); 3979 4432 unset($v_buffer); … … 4062 4515 4063 4516 // ----- Reading the file 4064 4517 $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); 4065 4518 4066 4519 // ----- Decompress the file 4067 4520 if (($p_string = @gzinflate($v_data)) === FALSE) { 4068 4521 // TBC … … 4163 4616 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); 4164 4617 $p_header['flag'] = $v_data['flag']; 4165 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).'\''); 4166 4621 $p_header['filename_len'] = $v_data['filename_len']; 4167 4622 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename_len : \''.$p_header['filename_len'].'\''); 4168 4623 … … 4182 4637 $v_day = $p_header['mdate'] & 0x001F; 4183 4638 4184 4639 // ----- Get UNIX date format 4185 $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);4640 $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 4186 4641 4187 4642 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4188 4643 } … … 4296 4751 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Offset : \''.$p_header['offset'].'\''); 4297 4752 4298 4753 // ----- Recuperate date in UNIX format 4299 if ($p_header['mdate'] && $p_header['mtime']) 4754 //if ($p_header['mdate'] && $p_header['mtime']) 4755 // TBC : bug : this was ignoring time with 0/0/0 4756 if (1) 4300 4757 { 4301 4758 // ----- Extract time 4302 4759 $v_hour = ($p_header['mtime'] & 0xF800) >> 11; … … 4309 4766 $v_day = $p_header['mdate'] & 0x001F; 4310 4767 4311 4768 // ----- Get UNIX date format 4312 $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);4769 $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 4313 4770 4314 4771 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); 4315 4772 } … … 4479 4936 $v_byte = @fread($this->zip_fd, 1); 4480 4937 4481 4938 // ----- Add the byte 4482 // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number 4483 // Otherwise on systems where we have 64bit integers the check below for the magic number will fail. 4484 $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); 4939 $v_bytes = ($v_bytes << 8) | Ord($v_byte); 4485 4940 4486 4941 // ----- Compare the bytes 4487 4942 if ($v_bytes == 0x504b0506) … … 4551 5006 } 4552 5007 4553 5008 // ----- Get comment 4554 if ($v_data['comment_size'] != 0) 5009 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment size : \''.$v_data['comment_size'].'\''); 5010 if ($v_data['comment_size'] != 0) { 4555 5011 $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); 5012 } 4556 5013 else 4557 5014 $p_central_dir['comment'] = ''; 4558 5015 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment : \''.$p_central_dir['comment'].'\''); … … 4814 5271 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 4815 5272 return $v_result; 4816 5273 } 4817 5274 4818 5275 // ----- Check that local file header is same as central file header 4819 5276 if ($this->privCheckFileHeaders($v_local_header, 4820 5277 $v_header_list[$i]) != 1) { … … 4907 5364 // TBC : I should test the result ... 4908 5365 //@rename($v_zip_temp_name, $this->zipname); 4909 5366 PclZipUtilRename($v_zip_temp_name, $this->zipname); 4910 5367 4911 5368 // ----- Destroy the temporary archive 4912 5369 unset($v_temp_zip); 4913 5370 } 4914 5371 4915 5372 // ----- Remove every files : reset the file 4916 5373 else if ($v_central_dir['entries'] != 0) { 4917 5374 $this->privCloseFd(); … … 5326 5783 { 5327 5784 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDecrypt', "size=".$p_size.""); 5328 5785 $v_result=1; 5329 5786 5330 5787 // ----- To Be Modified ;-) 5331 5788 $v_pwd = "test"; 5332 5789 5333 5790 $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header, 5334 5791 $p_crc, $v_pwd); 5335 5792 5336 5793 // ----- Return 5337 5794 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 5338 5795 return $v_result; … … 5482 5939 } 5483 5940 } 5484 5941 } 5485 5942 5486 5943 // ----- Look for skip 5487 5944 if ($v_skip > 0) { 5488 5945 while ($v_skip > 0) { … … 5517 5974 { 5518 5975 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathInclusion", "dir='$p_dir', path='$p_path'"); 5519 5976 $v_result = 1; 5520 5977 5521 5978 // ----- Look for path beginning by ./ 5522 5979 if ( ($p_dir == '.') 5523 5980 || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { … … 5708 6165 function PclZipUtilOptionText($p_option) 5709 6166 { 5710 6167 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilOptionText", "option='".$p_option."'"); 5711 6168 5712 6169 $v_list = get_defined_constants(); 5713 6170 for (reset($v_list); $v_key = key($v_list); next($v_list)) { 5714 6171 $v_prefix = substr($v_key, 0, 10); … … 5720 6177 return $v_key; 5721 6178 } 5722 6179 } 5723 6180 5724 6181 $v_result = 'Unknown'; 5725 6182 5726 6183 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)