Changeset 3582 for trunk/admin
- Timestamp:
- Jul 15, 2009, 1:36:11 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/pclzip.lib.php
r3282 r3582 1 1 <?php 2 2 // -------------------------------------------------------------------------------- 3 // PhpConcept Library - Zip Module 2. 63 // PhpConcept Library - Zip Module 2.8 4 4 // -------------------------------------------------------------------------------- 5 5 // License GNU/LGPL - Vincent Blavet - March 2006 … … 40 40 } 41 41 42 43 $g_pclzip_version = "2.6"; 42 if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) { 43 define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 ); 44 } 45 46 47 $g_pclzip_version = "2.8"; 44 48 45 49 define( 'PCLZIP_ERR_USER_ABORTED', 2 ); … … 85 89 define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 ); 86 90 define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); 91 define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 ); 92 define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 ); 93 define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 ); 87 94 88 95 define( 'PCLZIP_ATT_FILE_NAME', 79001 ); … … 97 104 define( 'PCLZIP_CB_PRE_ADD', 78003 ); 98 105 define( 'PCLZIP_CB_POST_ADD', 78004 ); 99 106 /* For futur use 107 define( 'PCLZIP_CB_PRE_LIST', 78005 ); 108 define( 'PCLZIP_CB_POST_LIST', 78006 ); 109 define( 'PCLZIP_CB_PRE_DELETE', 78007 ); 110 define( 'PCLZIP_CB_POST_DELETE', 78008 ); 111 */ 100 112 101 113 class PclZip … … 151 163 PCLZIP_CB_POST_ADD => 'optional', 152 164 PCLZIP_OPT_NO_COMPRESSION => 'optional', 153 PCLZIP_OPT_COMMENT => 'optional' 165 PCLZIP_OPT_COMMENT => 'optional', 166 PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', 167 PCLZIP_OPT_TEMP_FILE_ON => 'optional', 168 PCLZIP_OPT_TEMP_FILE_OFF => 'optional' 154 169 )); 155 170 if ($v_result != 1) { … … 172 187 } 173 188 } 189 190 $this->privOptionDefaultThreshold($v_options); 174 191 175 192 $v_string_list = array(); … … 267 284 PCLZIP_OPT_COMMENT => 'optional', 268 285 PCLZIP_OPT_ADD_COMMENT => 'optional', 269 PCLZIP_OPT_PREPEND_COMMENT => 'optional' 286 PCLZIP_OPT_PREPEND_COMMENT => 'optional', 287 PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', 288 PCLZIP_OPT_TEMP_FILE_ON => 'optional', 289 PCLZIP_OPT_TEMP_FILE_OFF => 'optional' 270 290 )); 271 291 if ($v_result != 1) { … … 288 308 } 289 309 } 310 311 $this->privOptionDefaultThreshold($v_options); 290 312 291 313 $v_string_list = array(); … … 411 433 PCLZIP_OPT_REPLACE_NEWER => 'optional' 412 434 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' 413 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' 435 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', 436 PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', 437 PCLZIP_OPT_TEMP_FILE_ON => 'optional', 438 PCLZIP_OPT_TEMP_FILE_OFF => 'optional' 414 439 )); 415 440 if ($v_result != 1) { … … 448 473 } 449 474 } 475 476 $this->privOptionDefaultThreshold($v_options); 450 477 451 478 … … 500 527 PCLZIP_OPT_REPLACE_NEWER => 'optional' 501 528 ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' 502 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' 529 ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', 530 PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', 531 PCLZIP_OPT_TEMP_FILE_ON => 'optional', 532 PCLZIP_OPT_TEMP_FILE_OFF => 'optional' 503 533 )); 504 534 if ($v_result != 1) { … … 552 582 } 553 583 $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX]; 584 585 $this->privOptionDefaultThreshold($v_options); 554 586 555 587 if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) { … … 797 829 $v_result = true; 798 830 799 831 clearstatcache(); 800 832 801 833 $this->privErrorReset(); … … 842 874 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); 843 875 $i++; 876 break; 877 878 case PCLZIP_OPT_TEMP_FILE_THRESHOLD : 879 if (($i+1) >= $p_size) { 880 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 881 return PclZip::errorCode(); 882 } 883 884 if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { 885 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); 886 return PclZip::errorCode(); 887 } 888 889 $v_value = $p_options_list[$i+1]; 890 if ((!is_integer($v_value)) || ($v_value<0)) { 891 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); 892 return PclZip::errorCode(); 893 } 894 895 $v_result_list[$p_options_list[$i]] = $v_value*1048576; 896 $i++; 897 break; 898 899 case PCLZIP_OPT_TEMP_FILE_ON : 900 if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { 901 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); 902 return PclZip::errorCode(); 903 } 904 905 $v_result_list[$p_options_list[$i]] = true; 906 break; 907 908 case PCLZIP_OPT_TEMP_FILE_OFF : 909 if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) { 910 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'"); 911 return PclZip::errorCode(); 912 } 913 if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { 914 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'"); 915 return PclZip::errorCode(); 916 } 917 918 $v_result_list[$p_options_list[$i]] = true; 844 919 break; 845 920 … … 1014 1089 case PCLZIP_CB_PRE_ADD : 1015 1090 case PCLZIP_CB_POST_ADD : 1016 1091 /* for futur use 1092 case PCLZIP_CB_PRE_DELETE : 1093 case PCLZIP_CB_POST_DELETE : 1094 case PCLZIP_CB_PRE_LIST : 1095 case PCLZIP_CB_POST_LIST : 1096 */ 1017 1097 if (($i+1) >= $p_size) { 1018 1098 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); … … 1055 1135 } 1056 1136 } 1057 1137 1138 if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { 1139 1140 } 1141 1142 return $v_result; 1143 } 1144 1145 function privOptionDefaultThreshold(&$p_options) 1146 { 1147 $v_result=1; 1148 1149 if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) 1150 || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) { 1151 return $v_result; 1152 } 1153 1154 $v_memory_limit = ini_get('memory_limit'); 1155 $v_memory_limit = trim($v_memory_limit); 1156 $last = strtolower(substr($v_memory_limit, -1)); 1157 1158 if($last == 'g') 1159 $v_memory_limit = $v_memory_limit*1073741824; 1160 if($last == 'm') 1161 $v_memory_limit = $v_memory_limit*1048576; 1162 if($last == 'k') 1163 $v_memory_limit = $v_memory_limit*1024; 1164 1165 $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO); 1166 1167 1168 if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) { 1169 unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]); 1170 } 1171 1058 1172 return $v_result; 1059 1173 } … … 1170 1284 $v_descr = $p_filedescr_list[$i]; 1171 1285 1172 $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'] );1286 $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); 1173 1287 $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); 1174 1288 … … 1193 1307 1194 1308 else { 1195 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist s");1309 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist"); 1196 1310 1197 1311 return PclZip::errorCode(); … … 1495 1609 if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') 1496 1610 && (!file_exists($p_filedescr_list[$j]['filename']))) { 1497 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist s");1611 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); 1498 1612 return PclZip::errorCode(); 1499 1613 } … … 1531 1645 } 1532 1646 1533 1647 /* TBC : Removed 1648 if (isset($p_filedescr['stored_filename'])) { 1649 $v_stored_filename = $p_filedescr['stored_filename']; 1650 } 1651 else { 1652 $v_stored_filename = $p_filedescr['stored_filename']; 1653 } 1654 */ 1534 1655 1535 1656 clearstatcache(); … … 1572 1693 } 1573 1694 else if ($p_filedescr['type'] == 'virtual_file') { 1574 $p_header['mtime'] = mktime();1695 $p_header['mtime'] = time(); 1575 1696 } 1576 1697 else { … … 1613 1734 if ($p_header['status'] == 'ok') { 1614 1735 1615 if ( ($p_filedescr['type'] == 'file') 1616 || ($p_filedescr['type'] == 'virtual_file')) { 1617 1618 if ($p_filedescr['type'] == 'file') { 1619 1620 if (($v_file = @fopen($p_filename, "rb")) == 0) { 1621 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); 1622 return PclZip::errorCode(); 1623 } 1624 1625 $v_content = @fread($v_file, $p_header['size']); 1626 1627 @fclose($v_file); 1628 } 1629 else if ($p_filedescr['type'] == 'virtual_file') { 1630 $v_content = $p_filedescr['content']; 1631 } 1736 if ($p_filedescr['type'] == 'file') { 1737 if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) 1738 && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) 1739 || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) 1740 && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { 1741 $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); 1742 if ($v_result < PCLZIP_ERR_NO_ERROR) { 1743 return $v_result; 1744 } 1745 } 1746 1747 else { 1748 1749 if (($v_file = @fopen($p_filename, "rb")) == 0) { 1750 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); 1751 return PclZip::errorCode(); 1752 } 1753 1754 $v_content = @fread($v_file, $p_header['size']); 1755 1756 @fclose($v_file); 1632 1757 1633 1758 $p_header['crc'] = @crc32($v_content); … … 1645 1770 } 1646 1771 1647 1648 1649 1772 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { 1650 1773 @fclose($v_file); … … 1653 1776 1654 1777 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); 1778 1779 } 1780 1781 } 1782 1783 else if ($p_filedescr['type'] == 'virtual_file') { 1784 1785 $v_content = $p_filedescr['content']; 1786 1787 $p_header['crc'] = @crc32($v_content); 1788 1789 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { 1790 $p_header['compressed_size'] = $p_header['size']; 1791 $p_header['compression'] = 0; 1792 } 1793 1794 else { 1795 $v_content = @gzdeflate($v_content); 1796 1797 $p_header['compressed_size'] = strlen($v_content); 1798 $p_header['compression'] = 8; 1799 } 1800 1801 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { 1802 @fclose($v_file); 1803 return $v_result; 1804 } 1805 1806 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); 1655 1807 } 1656 1808 … … 1661 1813 1662 1814 $p_header['size'] = 0; 1663 $p_header['external'] = 0x00000010; 1815 1664 1816 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) 1665 1817 { … … 1684 1836 } 1685 1837 1838 function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) 1839 { 1840 $v_result=PCLZIP_ERR_NO_ERROR; 1841 1842 $p_filename = $p_filedescr['filename']; 1843 1844 1845 if (($v_file = @fopen($p_filename, "rb")) == 0) { 1846 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); 1847 return PclZip::errorCode(); 1848 } 1849 1850 $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; 1851 if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { 1852 fclose($v_file); 1853 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); 1854 return PclZip::errorCode(); 1855 } 1856 1857 $v_size = filesize($p_filename); 1858 while ($v_size != 0) { 1859 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 1860 $v_buffer = @fread($v_file, $v_read_size); 1861 @gzputs($v_file_compressed, $v_buffer, $v_read_size); 1862 $v_size -= $v_read_size; 1863 } 1864 1865 @fclose($v_file); 1866 @gzclose($v_file_compressed); 1867 1868 if (filesize($v_gzip_temp_name) < 18) { 1869 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); 1870 return PclZip::errorCode(); 1871 } 1872 1873 if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { 1874 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); 1875 return PclZip::errorCode(); 1876 } 1877 1878 $v_binary_data = @fread($v_file_compressed, 10); 1879 $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data); 1880 1881 $v_data_header['os'] = bin2hex($v_data_header['os']); 1882 1883 @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8); 1884 $v_binary_data = @fread($v_file_compressed, 8); 1885 $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data); 1886 1887 $p_header['compression'] = ord($v_data_header['cm']); 1888 $p_header['crc'] = $v_data_footer['crc']; 1889 $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18; 1890 1891 @fclose($v_file_compressed); 1892 1893 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { 1894 return $v_result; 1895 } 1896 1897 if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) 1898 { 1899 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); 1900 return PclZip::errorCode(); 1901 } 1902 1903 fseek($v_file_compressed, 10); 1904 $v_size = $p_header['compressed_size']; 1905 while ($v_size != 0) 1906 { 1907 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 1908 $v_buffer = @fread($v_file_compressed, $v_read_size); 1909 @fwrite($this->zip_fd, $v_buffer, $v_read_size); 1910 $v_size -= $v_read_size; 1911 } 1912 1913 @fclose($v_file_compressed); 1914 1915 @unlink($v_gzip_temp_name); 1916 1917 return $v_result; 1918 } 1919 1686 1920 function privCalculateStoredFilename(&$p_filedescr, &$p_options) 1687 1921 { … … 1709 1943 1710 1944 if (isset($p_filedescr['new_full_name'])) { 1711 $v_stored_filename = $p_filedescr['new_full_name'];1945 $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']); 1712 1946 } 1713 1947 … … 1758 1992 } 1759 1993 } 1994 1995 $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename); 1996 1760 1997 if ($p_add_dir != "") { 1761 1998 if (substr($p_add_dir, -1) == "/") … … 1916 2153 $v_result=1; 1917 2154 1918 $p_info['filename'] = $p_header['filename']; 1919 $p_info['stored_filename'] = $p_header['stored_filename']; 2155 $v_temp_path = PclZipUtilPathReduction($p_header['filename']); 2156 $p_info['filename'] = $v_temp_path; 2157 $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']); 2158 $p_info['stored_filename'] = $v_temp_path; 1920 2159 $p_info['size'] = $p_header['size']; 1921 2160 $p_info['compressed_size'] = $p_header['compressed_size']; … … 2059 2298 } 2060 2299 2061 2300 if ( ($v_extract) 2062 2301 && ( ($v_header['compression'] != 8) 2063 2302 && ($v_header['compression'] != 0))) { … … 2078 2317 } 2079 2318 2080 2319 if (($v_extract) && (($v_header['flag'] & 1) == 1)) { 2081 2320 $v_header['status'] = 'unsupported_encryption'; 2082 2321 … … 2297 2536 2298 2537 return PclZip::errorCode(); 2299 }2538 } 2300 2539 } 2301 2540 else if (!is_writeable($p_entry['filename'])) … … 2312 2551 2313 2552 return PclZip::errorCode(); 2314 }2553 } 2315 2554 } 2316 2555 … … 2319 2558 if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) 2320 2559 && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { 2321 }2322 else {2560 } 2561 else { 2323 2562 $p_entry['status'] = "newer_exist"; 2324 2563 … … 2331 2570 2332 2571 return PclZip::errorCode(); 2333 }2334 }2572 } 2573 } 2335 2574 } 2336 2575 else { … … 2346 2585 $v_dir_to_check = dirname($p_entry['filename']); 2347 2586 2348 if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {2349 2350 $p_entry['status'] = "path_creation_fail";2351 2352 $v_result = 1;2353 }2354 }2587 if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { 2588 2589 $p_entry['status'] = "path_creation_fail"; 2590 2591 $v_result = 1; 2592 } 2593 } 2355 2594 } 2356 2595 … … 2361 2600 if ($p_entry['compression'] == 0) { 2362 2601 2363 2602 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) 2364 2603 { 2365 2604 … … 2375 2614 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 2376 2615 $v_buffer = @fread($this->zip_fd, $v_read_size); 2377 2616 /* Try to speed up the code 2617 $v_binary_data = pack('a'.$v_read_size, $v_buffer); 2618 @fwrite($v_dest_file, $v_binary_data, $v_read_size); 2619 */ 2378 2620 @fwrite($v_dest_file, $v_buffer, $v_read_size); 2379 2621 $v_size -= $v_read_size; … … 2388 2630 else { 2389 2631 if (($p_entry['flag'] & 1) == 1) { 2390 2391 } 2632 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.'); 2633 return PclZip::errorCode(); 2634 } 2635 2636 2637 if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) 2638 && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) 2639 || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) 2640 && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) { 2641 $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options); 2642 if ($v_result < PCLZIP_ERR_NO_ERROR) { 2643 return $v_result; 2644 } 2645 } 2646 2392 2647 else { 2393 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 2394 } 2648 2395 2649 2396 $v_file_content = @gzinflate($v_buffer); 2397 unset($v_buffer); 2398 if ($v_file_content === FALSE) { 2399 2400 $p_entry['status'] = "error"; 2650 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 2401 2651 2402 return $v_result; 2403 } 2404 2405 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { 2406 2407 $p_entry['status'] = "write_error"; 2408 2409 return $v_result; 2410 } 2411 2412 @fwrite($v_dest_file, $v_file_content, $p_entry['size']); 2413 unset($v_file_content); 2414 2415 @fclose($v_dest_file); 2652 $v_file_content = @gzinflate($v_buffer); 2653 unset($v_buffer); 2654 if ($v_file_content === FALSE) { 2655 2656 $p_entry['status'] = "error"; 2657 2658 return $v_result; 2659 } 2660 2661 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { 2662 2663 $p_entry['status'] = "write_error"; 2664 2665 return $v_result; 2666 } 2667 2668 @fwrite($v_dest_file, $v_file_content, $p_entry['size']); 2669 unset($v_file_content); 2670 2671 @fclose($v_dest_file); 2672 2673 } 2416 2674 2417 2675 @touch($p_entry['filename'], $p_entry['mtime']); … … 2426 2684 } 2427 2685 2428 2686 if ($p_entry['status'] == "aborted") { 2429 2687 $p_entry['status'] = "skipped"; 2430 2688 } … … 2442 2700 } 2443 2701 2702 return $v_result; 2703 } 2704 2705 function privExtractFileUsingTempFile(&$p_entry, &$p_options) 2706 { 2707 $v_result=1; 2708 2709 $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; 2710 if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) { 2711 fclose($v_file); 2712 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); 2713 return PclZip::errorCode(); 2714 } 2715 2716 2717 $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3)); 2718 @fwrite($v_dest_file, $v_binary_data, 10); 2719 2720 $v_size = $p_entry['compressed_size']; 2721 while ($v_size != 0) 2722 { 2723 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 2724 $v_buffer = @fread($this->zip_fd, $v_read_size); 2725 @fwrite($v_dest_file, $v_buffer, $v_read_size); 2726 $v_size -= $v_read_size; 2727 } 2728 2729 $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']); 2730 @fwrite($v_dest_file, $v_binary_data, 8); 2731 2732 @fclose($v_dest_file); 2733 2734 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { 2735 $p_entry['status'] = "write_error"; 2736 return $v_result; 2737 } 2738 2739 if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) { 2740 @fclose($v_dest_file); 2741 $p_entry['status'] = "read_error"; 2742 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); 2743 return PclZip::errorCode(); 2744 } 2745 2746 2747 $v_size = $p_entry['size']; 2748 while ($v_size != 0) { 2749 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); 2750 $v_buffer = @gzread($v_src_file, $v_read_size); 2751 @fwrite($v_dest_file, $v_buffer, $v_read_size); 2752 $v_size -= $v_read_size; 2753 } 2754 @fclose($v_dest_file); 2755 @gzclose($v_src_file); 2756 2757 @unlink($v_gzip_temp_name); 2758 2444 2759 return $v_result; 2445 2760 } … … 2500 2815 } 2501 2816 2502 2817 if ($p_entry['status'] == "aborted") { 2503 2818 $p_entry['status'] = "skipped"; 2504 2819 } … … 2613 2928 $v_day = $p_header['mdate'] & 0x001F; 2614 2929 2615 $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);2930 $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); 2616 2931 2617 2932 } … … 2708 3023 $v_result=1; 2709 3024 2710 2711 }2712 if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {2713 }2714 if ($p_local_header['flag'] != $p_central_header['flag']) {2715 }2716 if ($p_local_header['compression'] != $p_central_header['compression']) {2717 }2718 if ($p_local_header['mtime'] != $p_central_header['mtime']) {2719 }2720 if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {2721 }3025 if ($p_local_header['filename'] != $p_central_header['filename']) { 3026 } 3027 if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { 3028 } 3029 if ($p_local_header['flag'] != $p_central_header['flag']) { 3030 } 3031 if ($p_local_header['compression'] != $p_central_header['compression']) { 3032 } 3033 if ($p_local_header['mtime'] != $p_central_header['mtime']) { 3034 } 3035 if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { 3036 } 2722 3037 2723 3038 if (($p_local_header['flag'] & 8) == 8) { 2724 $p_local_header['size'] = $p_central_header['size'];2725 $p_local_header['compressed_size'] = $p_central_header['compressed_size'];2726 $p_local_header['crc'] = $p_central_header['crc'];2727 }3039 $p_local_header['size'] = $p_central_header['size']; 3040 $p_local_header['compressed_size'] = $p_central_header['compressed_size']; 3041 $p_local_header['crc'] = $p_central_header['crc']; 3042 } 2728 3043 2729 3044 return $v_result; … … 2764 3079 2765 3080 if (!$v_found) { 2766 $v_maximum_size = 65557;if ($v_maximum_size > $v_size)3081 if ($v_maximum_size > $v_size) 2767 3082 $v_maximum_size = $v_size; 2768 3083 @fseek($this->zip_fd, $v_size-$v_maximum_size); … … 2814 3129 if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { 2815 3130 2816 3131 if (0) { 2817 3132 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 2818 3133 'The central dir is not at the end of the archive.' … … 2899 3214 $v_found = true; 2900 3215 } 2901 elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) 3216 elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ 2902 3217 && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { 2903 3218 $v_found = true; … … 3311 3626 } 3312 3627 3313 function privDecrypt($p_encryption_header, &$p_buffer, $p_size, $p_crc)3314 {3315 $v_result=1;3316 3317 $v_pwd = "test";3318 3319 $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header,3320 $p_crc, $v_pwd);3321 3322 return $v_result;3323 }3324 3325 3628 function privDisableMagicQuotes() 3326 3629 { … … 3336 3639 } 3337 3640 3338 3339 3340 3641 $this->magic_quotes_status = @get_magic_quotes_runtime(); 3642 3643 if ($this->magic_quotes_status == 1) { 3341 3644 @set_magic_quotes_runtime(0); 3342 3645 } … … 3358 3661 } 3359 3662 3360 3663 if ($this->magic_quotes_status == 1) { 3361 3664 @set_magic_quotes_runtime($this->magic_quotes_status); 3362 3665 } … … 3382 3685 } 3383 3686 else if ($v_list[$i] == "") { 3384 3687 if ($i == 0) { 3385 3688 $v_result = "/".$v_result; 3386 3689 if ($v_skip > 0) { 3387 3690 $v_result = $p_dir; 3388 3691 $v_skip = 0; 3389 3692 } 3390 3693 } 3391 3694 else if ($i == (sizeof($v_list)-1)) { 3392 3695 $v_result = $v_list[$i]; 3393 3696 } 3394 3697 else { 3395 3698 } 3396 3699 } 3397 3700 else { 3398 3701 if ($v_skip > 0) { 3399 3702 $v_skip--; 3400 3703 } … … 3540 3843 $v_list = get_defined_constants(); 3541 3844 for (reset($v_list); $v_key = key($v_list); next($v_list)) { 3542 $v_prefix = substr($v_key, 0, 10);3543 if (( ($v_prefix == 'PCLZIP_OPT')3544 || ($v_prefix == 'PCLZIP_CB_')3545 || ($v_prefix == 'PCLZIP_ATT'))3546 && ($v_list[$v_key] == $p_option)) {3547 3845 $v_prefix = substr($v_key, 0, 10); 3846 if (( ($v_prefix == 'PCLZIP_OPT') 3847 || ($v_prefix == 'PCLZIP_CB_') 3848 || ($v_prefix == 'PCLZIP_ATT')) 3849 && ($v_list[$v_key] == $p_option)) { 3850 return $v_key; 3548 3851 } 3549 3852 }
Note: See TracChangeset
for help on using the changeset viewer.