1533 if (($i+1) >= $p_size) { |
1450 if (($i+1) >= $p_size) { |
1534 // ----- Error log |
1451 // ----- Error log |
1535 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1452 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1536 |
1453 |
1537 // ----- Return |
1454 // ----- Return |
1538 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1539 return PclZip::errorCode(); |
1455 return PclZip::errorCode(); |
1540 } |
1456 } |
1541 |
1457 |
1542 // ----- Get the value |
1458 // ----- Get the value |
1543 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
1459 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
1544 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); |
|
1545 $i++; |
1460 $i++; |
1546 break; |
1461 break; |
1547 |
1462 |
1548 case PCLZIP_OPT_TEMP_FILE_THRESHOLD : |
1463 case PCLZIP_OPT_TEMP_FILE_THRESHOLD : |
1549 // ----- Check the number of parameters |
1464 // ----- Check the number of parameters |
1550 if (($i+1) >= $p_size) { |
1465 if (($i+1) >= $p_size) { |
1551 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1466 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1552 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1553 return PclZip::errorCode(); |
1467 return PclZip::errorCode(); |
1554 } |
1468 } |
1555 |
1469 |
1556 // ----- Check for incompatible options |
1470 // ----- Check for incompatible options |
1557 if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
1471 if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
1558 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
1472 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
1559 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1560 return PclZip::errorCode(); |
1473 return PclZip::errorCode(); |
1561 } |
1474 } |
1562 |
1475 |
1563 // ----- Check the value |
1476 // ----- Check the value |
1564 $v_value = $p_options_list[$i+1]; |
1477 $v_value = $p_options_list[$i+1]; |
1565 if ((!is_integer($v_value)) || ($v_value<0)) { |
1478 if ((!is_integer($v_value)) || ($v_value<0)) { |
1566 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1479 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1567 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1568 return PclZip::errorCode(); |
1480 return PclZip::errorCode(); |
1569 } |
1481 } |
1570 |
1482 |
1571 // ----- Get the value (and convert it in bytes) |
1483 // ----- Get the value (and convert it in bytes) |
1572 $v_result_list[$p_options_list[$i]] = $v_value*1048576; |
1484 $v_result_list[$p_options_list[$i]] = $v_value*1048576; |
1573 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); |
|
1574 $i++; |
1485 $i++; |
1575 break; |
1486 break; |
1576 |
1487 |
1577 case PCLZIP_OPT_TEMP_FILE_ON : |
1488 case PCLZIP_OPT_TEMP_FILE_ON : |
1578 // ----- Check for incompatible options |
1489 // ----- Check for incompatible options |
1579 if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
1490 if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
1580 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
1491 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
1581 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1582 return PclZip::errorCode(); |
1492 return PclZip::errorCode(); |
1583 } |
1493 } |
1584 |
1494 |
1585 $v_result_list[$p_options_list[$i]] = true; |
1495 $v_result_list[$p_options_list[$i]] = true; |
1586 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); |
|
1587 break; |
1496 break; |
1588 |
1497 |
1589 case PCLZIP_OPT_TEMP_FILE_OFF : |
1498 case PCLZIP_OPT_TEMP_FILE_OFF : |
1590 // ----- Check for incompatible options |
1499 // ----- Check for incompatible options |
1591 if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) { |
1500 if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) { |
1592 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'"); |
1501 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'"); |
1593 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1594 return PclZip::errorCode(); |
1502 return PclZip::errorCode(); |
1595 } |
1503 } |
1596 // ----- Check for incompatible options |
1504 // ----- Check for incompatible options |
1597 if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { |
1505 if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { |
1598 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'"); |
1506 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'"); |
1599 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1600 return PclZip::errorCode(); |
1507 return PclZip::errorCode(); |
1601 } |
1508 } |
1602 |
1509 |
1603 $v_result_list[$p_options_list[$i]] = true; |
1510 $v_result_list[$p_options_list[$i]] = true; |
1604 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); |
|
1605 break; |
1511 break; |
1606 |
1512 |
1607 case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : |
1513 case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : |
1608 // ----- Check the number of parameters |
1514 // ----- Check the number of parameters |
1609 if (($i+1) >= $p_size) { |
1515 if (($i+1) >= $p_size) { |
1610 // ----- Error log |
1516 // ----- Error log |
1611 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1517 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1612 |
1518 |
1613 // ----- Return |
1519 // ----- Return |
1614 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1615 return PclZip::errorCode(); |
1520 return PclZip::errorCode(); |
1616 } |
1521 } |
1617 |
1522 |
1618 // ----- Get the value |
1523 // ----- Get the value |
1619 if ( is_string($p_options_list[$i+1]) |
1524 if ( is_string($p_options_list[$i+1]) |
1620 && ($p_options_list[$i+1] != '')) { |
1525 && ($p_options_list[$i+1] != '')) { |
1621 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
1526 $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
1622 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); |
|
1623 $i++; |
1527 $i++; |
1624 } |
1528 } |
1625 else { |
1529 else { |
1626 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored."); |
|
1627 } |
1530 } |
1628 break; |
1531 break; |
1629 |
1532 |
1630 // ----- Look for options that request an array of string for value |
1533 // ----- Look for options that request an array of string for value |
1631 case PCLZIP_OPT_BY_NAME : |
1534 case PCLZIP_OPT_BY_NAME : |
1730 if (($i+1) >= $p_size) { |
1627 if (($i+1) >= $p_size) { |
1731 // ----- Error log |
1628 // ----- Error log |
1732 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1629 PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1733 |
1630 |
1734 // ----- Return |
1631 // ----- Return |
1735 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1736 return PclZip::errorCode(); |
1632 return PclZip::errorCode(); |
1737 } |
1633 } |
1738 |
1634 |
1739 // ----- Get the value |
1635 // ----- Get the value |
1740 $v_work_list = array(); |
1636 $v_work_list = array(); |
1741 if (is_string($p_options_list[$i+1])) { |
1637 if (is_string($p_options_list[$i+1])) { |
1742 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'"); |
|
1743 |
1638 |
1744 // ----- Remove spaces |
1639 // ----- Remove spaces |
1745 $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); |
1640 $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); |
1746 |
1641 |
1747 // ----- Parse items |
1642 // ----- Parse items |
1748 $v_work_list = explode(",", $p_options_list[$i+1]); |
1643 $v_work_list = explode(",", $p_options_list[$i+1]); |
1749 } |
1644 } |
1750 else if (is_integer($p_options_list[$i+1])) { |
1645 else if (is_integer($p_options_list[$i+1])) { |
1751 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an integer '".$p_options_list[$i+1]."'"); |
|
1752 $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; |
1646 $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; |
1753 } |
1647 } |
1754 else if (is_array($p_options_list[$i+1])) { |
1648 else if (is_array($p_options_list[$i+1])) { |
1755 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array"); |
|
1756 $v_work_list = $p_options_list[$i+1]; |
1649 $v_work_list = $p_options_list[$i+1]; |
1757 } |
1650 } |
1758 else { |
1651 else { |
1759 // ----- Error log |
1652 // ----- Error log |
1760 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1653 PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
1761 |
1654 |
1762 // ----- Return |
1655 // ----- Return |
1763 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
1764 return PclZip::errorCode(); |
1656 return PclZip::errorCode(); |
1765 } |
1657 } |
1766 |
1658 |
1767 // ----- Reduce the index list |
1659 // ----- Reduce the index list |
1768 // each index item in the list must be a couple with a start and |
1660 // each index item in the list must be a couple with a start and |
1769 // an end value : [0,3], [5-5], [8-10], ... |
1661 // an end value : [0,3], [5-5], [8-10], ... |
1770 // ----- Check the format of each item |
1662 // ----- Check the format of each item |
1771 $v_sort_flag=false; |
1663 $v_sort_flag=false; |
1772 $v_sort_value=0; |
1664 $v_sort_value=0; |
1773 for ($j=0; $j<sizeof($v_work_list); $j++) { |
1665 for ($j=0; $j<sizeof($v_work_list); $j++) { |
1774 // ----- Explode the item |
1666 // ----- Explode the item |
1775 $v_item_list = explode("-", $v_work_list[$j]); |
1667 $v_item_list = explode("-", $v_work_list[$j]); |
1776 $v_size_item_list = sizeof($v_item_list); |
1668 $v_size_item_list = sizeof($v_item_list); |
1777 |
1669 |
1778 // ----- TBC : Here we might check that each item is a |
1670 // ----- TBC : Here we might check that each item is a |
1779 // real integer ... |
1671 // real integer ... |
1780 |
1672 |
1781 // ----- Look for single value |
1673 // ----- Look for single value |
1782 if ($v_size_item_list == 1) { |
1674 if ($v_size_item_list == 1) { |
1783 // ----- Set the option value |
1675 // ----- Set the option value |
1784 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
1676 $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
1785 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; |
1677 $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; |
1998 // 1 on success. |
1867 // 1 on success. |
1999 // 0 on failure. |
1868 // 0 on failure. |
2000 // -------------------------------------------------------------------------------- |
1869 // -------------------------------------------------------------------------------- |
2001 function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) |
1870 function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) |
2002 { |
1871 { |
2003 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", ""); |
|
2004 $v_result=1; |
1872 $v_result=1; |
2005 |
1873 |
2006 // ----- For each file in the list check the attributes |
1874 // ----- For each file in the list check the attributes |
2007 foreach ($p_file_list as $v_key => $v_value) { |
1875 foreach ($p_file_list as $v_key => $v_value) { |
2008 |
1876 |
2009 // ----- Check if the option is supported |
1877 // ----- Check if the option is supported |
2010 if (!isset($v_requested_options[$v_key])) { |
1878 if (!isset($v_requested_options[$v_key])) { |
2011 // ----- Error log |
1879 // ----- Error log |
2012 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); |
1880 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); |
2013 |
1881 |
2014 // ----- Return |
1882 // ----- Return |
2015 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2016 return PclZip::errorCode(); |
1883 return PclZip::errorCode(); |
2017 } |
1884 } |
2018 |
1885 |
2019 // ----- Look for attribute |
1886 // ----- Look for attribute |
2020 switch ($v_key) { |
1887 switch ($v_key) { |
2021 case PCLZIP_ATT_FILE_NAME : |
1888 case PCLZIP_ATT_FILE_NAME : |
2022 if (!is_string($v_value)) { |
1889 if (!is_string($v_value)) { |
2023 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
1890 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
2024 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2025 return PclZip::errorCode(); |
1891 return PclZip::errorCode(); |
2026 } |
1892 } |
2027 |
1893 |
2028 $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); |
1894 $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); |
2029 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); |
1895 |
2030 |
|
2031 if ($p_filedescr['filename'] == '') { |
1896 if ($p_filedescr['filename'] == '') { |
2032 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
1897 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
2033 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2034 return PclZip::errorCode(); |
1898 return PclZip::errorCode(); |
2035 } |
1899 } |
2036 |
1900 |
2037 break; |
1901 break; |
2038 |
1902 |
2039 case PCLZIP_ATT_FILE_NEW_SHORT_NAME : |
1903 case PCLZIP_ATT_FILE_NEW_SHORT_NAME : |
2040 if (!is_string($v_value)) { |
1904 if (!is_string($v_value)) { |
2041 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
1905 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
2042 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2043 return PclZip::errorCode(); |
1906 return PclZip::errorCode(); |
2044 } |
1907 } |
2045 |
1908 |
2046 $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); |
1909 $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); |
2047 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); |
|
2048 |
1910 |
2049 if ($p_filedescr['new_short_name'] == '') { |
1911 if ($p_filedescr['new_short_name'] == '') { |
2050 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
1912 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
2051 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2052 return PclZip::errorCode(); |
1913 return PclZip::errorCode(); |
2053 } |
1914 } |
2054 break; |
1915 break; |
2055 |
1916 |
2056 case PCLZIP_ATT_FILE_NEW_FULL_NAME : |
1917 case PCLZIP_ATT_FILE_NEW_FULL_NAME : |
2057 if (!is_string($v_value)) { |
1918 if (!is_string($v_value)) { |
2058 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
1919 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
2059 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2060 return PclZip::errorCode(); |
1920 return PclZip::errorCode(); |
2061 } |
1921 } |
2062 |
1922 |
2063 $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); |
1923 $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); |
2064 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); |
|
2065 |
1924 |
2066 if ($p_filedescr['new_full_name'] == '') { |
1925 if ($p_filedescr['new_full_name'] == '') { |
2067 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
1926 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
2068 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2069 return PclZip::errorCode(); |
1927 return PclZip::errorCode(); |
2070 } |
1928 } |
2071 break; |
1929 break; |
2072 |
1930 |
2073 // ----- Look for options that takes a string |
1931 // ----- Look for options that takes a string |
2074 case PCLZIP_ATT_FILE_COMMENT : |
1932 case PCLZIP_ATT_FILE_COMMENT : |
2075 if (!is_string($v_value)) { |
1933 if (!is_string($v_value)) { |
2076 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
1934 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
2077 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2078 return PclZip::errorCode(); |
1935 return PclZip::errorCode(); |
2079 } |
1936 } |
2080 |
1937 |
2081 $p_filedescr['comment'] = $v_value; |
1938 $p_filedescr['comment'] = $v_value; |
2082 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); |
|
2083 break; |
1939 break; |
2084 |
1940 |
2085 case PCLZIP_ATT_FILE_MTIME : |
1941 case PCLZIP_ATT_FILE_MTIME : |
2086 if (!is_integer($v_value)) { |
1942 if (!is_integer($v_value)) { |
2087 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
1943 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
2088 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2089 return PclZip::errorCode(); |
1944 return PclZip::errorCode(); |
2090 } |
1945 } |
2091 |
1946 |
2092 $p_filedescr['mtime'] = $v_value; |
1947 $p_filedescr['mtime'] = $v_value; |
2093 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); |
|
2094 break; |
1948 break; |
2095 |
1949 |
2096 case PCLZIP_ATT_FILE_CONTENT : |
1950 case PCLZIP_ATT_FILE_CONTENT : |
2097 $p_filedescr['content'] = $v_value; |
1951 $p_filedescr['content'] = $v_value; |
2098 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); |
|
2099 break; |
1952 break; |
2100 |
1953 |
2101 default : |
1954 default : |
2102 // ----- Error log |
1955 // ----- Error log |
2103 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
1956 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
2104 "Unknown parameter '".$v_key."'"); |
1957 "Unknown parameter '".$v_key."'"); |
2105 |
1958 |
2106 // ----- Return |
1959 // ----- Return |
2107 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2108 return PclZip::errorCode(); |
1960 return PclZip::errorCode(); |
2109 } |
1961 } |
2110 |
1962 |
2111 // ----- Look for mandatory options |
1963 // ----- Look for mandatory options |
2112 if ($v_requested_options !== false) { |
1964 if ($v_requested_options !== false) { |
2113 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
1965 for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
2114 // ----- Look for mandatory option |
1966 // ----- Look for mandatory option |
2115 if ($v_requested_options[$key] == 'mandatory') { |
1967 if ($v_requested_options[$key] == 'mandatory') { |
2116 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); |
|
2117 // ----- Look if present |
1968 // ----- Look if present |
2118 if (!isset($p_file_list[$key])) { |
1969 if (!isset($p_file_list[$key])) { |
2119 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
1970 PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
2120 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2121 return PclZip::errorCode(); |
1971 return PclZip::errorCode(); |
2122 } |
1972 } |
2123 } |
1973 } |
2124 } |
1974 } |
2125 } |
1975 } |
2126 |
1976 |
2127 // end foreach |
1977 // end foreach |
2128 } |
1978 } |
2129 |
1979 |
2130 // ----- Return |
1980 // ----- Return |
2131 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2132 return $v_result; |
1981 return $v_result; |
2133 } |
1982 } |
2134 // -------------------------------------------------------------------------------- |
1983 // -------------------------------------------------------------------------------- |
2135 |
1984 |
2136 // -------------------------------------------------------------------------------- |
1985 // -------------------------------------------------------------------------------- |
2138 // Description : |
1987 // Description : |
2139 // This method look for each item of the list to see if its a file, a folder |
1988 // This method look for each item of the list to see if its a file, a folder |
2140 // or a string to be added as file. For any other type of files (link, other) |
1989 // or a string to be added as file. For any other type of files (link, other) |
2141 // just ignore the item. |
1990 // just ignore the item. |
2142 // Then prepare the information that will be stored for that file. |
1991 // Then prepare the information that will be stored for that file. |
2143 // When its a folder, expand the folder with all the files that are in that |
1992 // When its a folder, expand the folder with all the files that are in that |
2144 // folder (recursively). |
1993 // folder (recursively). |
2145 // Parameters : |
1994 // Parameters : |
2146 // Return Values : |
1995 // Return Values : |
2147 // 1 on success. |
1996 // 1 on success. |
2148 // 0 on failure. |
1997 // 0 on failure. |
2149 // -------------------------------------------------------------------------------- |
1998 // -------------------------------------------------------------------------------- |
2150 function privFileDescrExpand(&$p_filedescr_list, &$p_options) |
1999 function privFileDescrExpand(&$p_filedescr_list, &$p_options) |
2151 { |
2000 { |
2152 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", ""); |
|
2153 $v_result=1; |
2001 $v_result=1; |
2154 |
2002 |
2155 // ----- Create a result list |
2003 // ----- Create a result list |
2156 $v_result_list = array(); |
2004 $v_result_list = array(); |
2157 |
2005 |
2158 // ----- Look each entry |
2006 // ----- Look each entry |
2159 for ($i=0; $i<sizeof($p_filedescr_list); $i++) { |
2007 for ($i=0; $i<sizeof($p_filedescr_list); $i++) { |
2160 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for file ".$i."."); |
2008 |
2161 |
|
2162 // ----- Get filedescr |
2009 // ----- Get filedescr |
2163 $v_descr = $p_filedescr_list[$i]; |
2010 $v_descr = $p_filedescr_list[$i]; |
2164 |
2011 |
2165 // ----- Reduce the filename |
2012 // ----- Reduce the filename |
2166 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'"); |
|
2167 $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); |
2013 $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); |
2168 $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); |
2014 $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); |
2169 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'"); |
2015 |
2170 |
|
2171 // ----- Look for real file or folder |
2016 // ----- Look for real file or folder |
2172 if (file_exists($v_descr['filename'])) { |
2017 if (file_exists($v_descr['filename'])) { |
2173 if (@is_file($v_descr['filename'])) { |
2018 if (@is_file($v_descr['filename'])) { |
2174 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file"); |
|
2175 $v_descr['type'] = 'file'; |
2019 $v_descr['type'] = 'file'; |
2176 } |
2020 } |
2177 else if (@is_dir($v_descr['filename'])) { |
2021 else if (@is_dir($v_descr['filename'])) { |
2178 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder"); |
|
2179 $v_descr['type'] = 'folder'; |
2022 $v_descr['type'] = 'folder'; |
2180 } |
2023 } |
2181 else if (@is_link($v_descr['filename'])) { |
2024 else if (@is_link($v_descr['filename'])) { |
2182 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link"); |
|
2183 // skip |
2025 // skip |
2184 continue; |
2026 continue; |
2185 } |
2027 } |
2186 else { |
2028 else { |
2187 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type"); |
|
2188 // skip |
2029 // skip |
2189 continue; |
2030 continue; |
2190 } |
2031 } |
2191 } |
2032 } |
2192 |
2033 |
2193 // ----- Look for string added as file |
2034 // ----- Look for string added as file |
2194 else if (isset($v_descr['content'])) { |
2035 else if (isset($v_descr['content'])) { |
2195 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a string added as a file"); |
|
2196 $v_descr['type'] = 'virtual_file'; |
2036 $v_descr['type'] = 'virtual_file'; |
2197 } |
2037 } |
2198 |
2038 |
2199 // ----- Missing file |
2039 // ----- Missing file |
2200 else { |
2040 else { |
2201 // ----- Error log |
2041 // ----- Error log |
2202 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exist"); |
|
2203 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist"); |
2042 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist"); |
2204 |
2043 |
2205 // ----- Return |
2044 // ----- Return |
2206 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2207 return PclZip::errorCode(); |
2045 return PclZip::errorCode(); |
2208 } |
2046 } |
2209 |
2047 |
2210 // ----- Calculate the stored filename |
2048 // ----- Calculate the stored filename |
2211 $this->privCalculateStoredFilename($v_descr, $p_options); |
2049 $this->privCalculateStoredFilename($v_descr, $p_options); |
2212 |
2050 |
2213 // ----- Add the descriptor in result list |
2051 // ----- Add the descriptor in result list |
2214 $v_result_list[sizeof($v_result_list)] = $v_descr; |
2052 $v_result_list[sizeof($v_result_list)] = $v_descr; |
2215 |
2053 |
2216 // ----- Look for folder |
2054 // ----- Look for folder |
2217 if ($v_descr['type'] == 'folder') { |
2055 if ($v_descr['type'] == 'folder') { |
2218 // ----- List of items in folder |
2056 // ----- List of items in folder |
2219 $v_dirlist_descr = array(); |
2057 $v_dirlist_descr = array(); |
2220 $v_dirlist_nb = 0; |
2058 $v_dirlist_nb = 0; |
2221 if ($v_folder_handler = @opendir($v_descr['filename'])) { |
2059 if ($v_folder_handler = @opendir($v_descr['filename'])) { |
2222 while (($v_item_handler = @readdir($v_folder_handler)) !== false) { |
2060 while (($v_item_handler = @readdir($v_folder_handler)) !== false) { |
2223 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory"); |
|
2224 |
2061 |
2225 // ----- Skip '.' and '..' |
2062 // ----- Skip '.' and '..' |
2226 if (($v_item_handler == '.') || ($v_item_handler == '..')) { |
2063 if (($v_item_handler == '.') || ($v_item_handler == '..')) { |
2227 continue; |
2064 continue; |
2228 } |
2065 } |
2229 |
2066 |
2230 // ----- Compose the full filename |
2067 // ----- Compose the full filename |
2231 $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; |
2068 $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; |
2232 |
2069 |
2233 // ----- Look for different stored filename |
2070 // ----- Look for different stored filename |
2234 // Because the name of the folder was changed, the name of the |
2071 // Because the name of the folder was changed, the name of the |
2235 // files/sub-folders also change |
2072 // files/sub-folders also change |
2236 if ($v_descr['stored_filename'] != $v_descr['filename']) { |
2073 if (($v_descr['stored_filename'] != $v_descr['filename']) |
|
2074 && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { |
2237 if ($v_descr['stored_filename'] != '') { |
2075 if ($v_descr['stored_filename'] != '') { |
2238 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; |
2076 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; |
2239 } |
2077 } |
2240 else { |
2078 else { |
2241 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; |
2079 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; |
2242 } |
2080 } |
2243 } |
2081 } |
2244 |
2082 |
2245 $v_dirlist_nb++; |
2083 $v_dirlist_nb++; |
2246 } |
2084 } |
2247 |
2085 |
2248 @closedir($v_folder_handler); |
2086 @closedir($v_folder_handler); |
2249 } |
2087 } |
2250 else { |
2088 else { |
2251 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped."); |
|
2252 // TBC : unable to open folder in read mode |
2089 // TBC : unable to open folder in read mode |
2253 } |
2090 } |
2254 |
2091 |
2255 // ----- Expand each element of the list |
2092 // ----- Expand each element of the list |
2256 if ($v_dirlist_nb != 0) { |
2093 if ($v_dirlist_nb != 0) { |
2257 // ----- Expand |
2094 // ----- Expand |
2258 if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { |
2095 if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { |
2259 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2260 return $v_result; |
2096 return $v_result; |
2261 } |
2097 } |
2262 |
2098 |
2263 // ----- Concat the resulting list |
2099 // ----- Concat the resulting list |
2264 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')"); |
|
2265 $v_result_list = array_merge($v_result_list, $v_dirlist_descr); |
2100 $v_result_list = array_merge($v_result_list, $v_dirlist_descr); |
2266 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'"); |
|
2267 } |
2101 } |
2268 else { |
2102 else { |
2269 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand."); |
2103 } |
2270 } |
2104 |
2271 |
|
2272 // ----- Free local array |
2105 // ----- Free local array |
2273 unset($v_dirlist_descr); |
2106 unset($v_dirlist_descr); |
2274 } |
2107 } |
2275 } |
2108 } |
2276 |
2109 |
2277 // ----- Get the result list |
2110 // ----- Get the result list |
2278 $p_filedescr_list = $v_result_list; |
2111 $p_filedescr_list = $v_result_list; |
2279 |
2112 |
2280 // ----- Return |
2113 // ----- Return |
2281 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2282 return $v_result; |
2114 return $v_result; |
2283 } |
2115 } |
2284 // -------------------------------------------------------------------------------- |
2116 // -------------------------------------------------------------------------------- |
2285 |
2117 |
2286 // -------------------------------------------------------------------------------- |
2118 // -------------------------------------------------------------------------------- |
2327 // Parameters : |
2156 // Parameters : |
2328 // Return Values : |
2157 // Return Values : |
2329 // -------------------------------------------------------------------------------- |
2158 // -------------------------------------------------------------------------------- |
2330 function privAdd($p_filedescr_list, &$p_result_list, &$p_options) |
2159 function privAdd($p_filedescr_list, &$p_result_list, &$p_options) |
2331 { |
2160 { |
2332 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list"); |
|
2333 $v_result=1; |
2161 $v_result=1; |
2334 $v_list_detail = array(); |
2162 $v_list_detail = array(); |
2335 |
2163 |
2336 // ----- Look if the archive exists or is empty |
2164 // ----- Look if the archive exists or is empty |
2337 if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) |
2165 if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) |
2338 { |
2166 { |
2339 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it."); |
|
2340 |
2167 |
2341 // ----- Do a create |
2168 // ----- Do a create |
2342 $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); |
2169 $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); |
2343 |
2170 |
2344 // ----- Return |
2171 // ----- Return |
2345 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2346 return $v_result; |
2172 return $v_result; |
2347 } |
2173 } |
2348 // ----- Magic quotes trick |
2174 // ----- Magic quotes trick |
2349 $this->privDisableMagicQuotes(); |
2175 $this->privDisableMagicQuotes(); |
2350 |
2176 |
2351 // ----- Open the zip file |
2177 // ----- Open the zip file |
2352 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); |
|
2353 if (($v_result=$this->privOpenFd('rb')) != 1) |
2178 if (($v_result=$this->privOpenFd('rb')) != 1) |
2354 { |
2179 { |
2355 // ----- Magic quotes trick |
2180 // ----- Magic quotes trick |
2356 $this->privSwapBackMagicQuotes(); |
2181 $this->privSwapBackMagicQuotes(); |
2357 |
2182 |
2358 // ----- Return |
2183 // ----- Return |
2359 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2360 return $v_result; |
2184 return $v_result; |
2361 } |
2185 } |
2362 |
2186 |
2363 // ----- Read the central directory informations |
2187 // ----- Read the central directory informations |
2364 $v_central_dir = array(); |
2188 $v_central_dir = array(); |
2365 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
2189 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
2366 { |
2190 { |
2367 $this->privCloseFd(); |
2191 $this->privCloseFd(); |
2368 $this->privSwapBackMagicQuotes(); |
2192 $this->privSwapBackMagicQuotes(); |
2369 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2370 return $v_result; |
2193 return $v_result; |
2371 } |
2194 } |
2372 |
2195 |
2373 // ----- Go to beginning of File |
2196 // ----- Go to beginning of File |
2374 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); |
|
2375 @rewind($this->zip_fd); |
2197 @rewind($this->zip_fd); |
2376 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); |
|
2377 |
2198 |
2378 // ----- Creates a temporay file |
2199 // ----- Creates a temporay file |
2379 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
2200 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
2380 |
2201 |
2381 // ----- Open the temporary file in write mode |
2202 // ----- Open the temporary file in write mode |
2382 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); |
|
2383 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
2203 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
2384 { |
2204 { |
2385 $this->privCloseFd(); |
2205 $this->privCloseFd(); |
2386 $this->privSwapBackMagicQuotes(); |
2206 $this->privSwapBackMagicQuotes(); |
2387 |
2207 |
2388 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
2208 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
2389 |
2209 |
2390 // ----- Return |
2210 // ----- Return |
2391 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2392 return PclZip::errorCode(); |
2211 return PclZip::errorCode(); |
2393 } |
2212 } |
2394 |
2213 |
2395 // ----- Copy the files from the archive to the temporary file |
2214 // ----- Copy the files from the archive to the temporary file |
2396 // TBC : Here I should better append the file and go back to erase the central dir |
2215 // TBC : Here I should better append the file and go back to erase the central dir |
2397 $v_size = $v_central_dir['offset']; |
2216 $v_size = $v_central_dir['offset']; |
2398 while ($v_size != 0) |
2217 while ($v_size != 0) |
2399 { |
2218 { |
2400 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
2219 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
2401 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); |
|
2402 $v_buffer = fread($this->zip_fd, $v_read_size); |
2220 $v_buffer = fread($this->zip_fd, $v_read_size); |
2403 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
2221 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
2404 $v_size -= $v_read_size; |
2222 $v_size -= $v_read_size; |
2405 } |
2223 } |
2406 |
2224 |
2639 { |
2441 { |
2640 // ----- Reset the file list |
2442 // ----- Reset the file list |
2641 unset($v_header_list); |
2443 unset($v_header_list); |
2642 |
2444 |
2643 // ----- Return |
2445 // ----- Return |
2644 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2645 return $v_result; |
2446 return $v_result; |
2646 } |
2447 } |
2647 |
2448 |
2648 // ----- Return |
2449 // ----- Return |
2649 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2650 return $v_result; |
2450 return $v_result; |
2651 } |
2451 } |
2652 // -------------------------------------------------------------------------------- |
2452 // -------------------------------------------------------------------------------- |
2653 |
2453 |
2654 // -------------------------------------------------------------------------------- |
2454 // -------------------------------------------------------------------------------- |
2655 // Function : privAddFileList() |
2455 // Function : privAddFileList() |
2656 // Description : |
2456 // Description : |
2657 // Parameters : |
2457 // Parameters : |
2658 // $p_filedescr_list : An array containing the file description |
2458 // $p_filedescr_list : An array containing the file description |
2659 // or directory names to add in the zip |
2459 // or directory names to add in the zip |
2660 // $p_result_list : list of added files with their properties (specially the status field) |
2460 // $p_result_list : list of added files with their properties (specially the status field) |
2661 // Return Values : |
2461 // Return Values : |
2662 // -------------------------------------------------------------------------------- |
2462 // -------------------------------------------------------------------------------- |
2663 function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) |
2463 function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) |
2664 { |
2464 { |
2665 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "filedescr_list"); |
|
2666 $v_result=1; |
2465 $v_result=1; |
2667 $v_header = array(); |
2466 $v_header = array(); |
2668 |
2467 |
2669 // ----- Recuperate the current number of elt in list |
2468 // ----- Recuperate the current number of elt in list |
2670 $v_nb = sizeof($p_result_list); |
2469 $v_nb = sizeof($p_result_list); |
2671 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Before add, list have ".$v_nb." elements"); |
|
2672 |
2470 |
2673 // ----- Loop on the files |
2471 // ----- Loop on the files |
2674 for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { |
2472 for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { |
2675 // ----- Format the filename |
2473 // ----- Format the filename |
2676 $p_filedescr_list[$j]['filename'] |
2474 $p_filedescr_list[$j]['filename'] |
2677 = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); |
2475 = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); |
2678 |
2476 |
2679 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'"); |
|
2680 |
2477 |
2681 // ----- Skip empty file names |
2478 // ----- Skip empty file names |
2682 // TBC : Can this be possible ? not checked in DescrParseAtt ? |
2479 // TBC : Can this be possible ? not checked in DescrParseAtt ? |
2683 if ($p_filedescr_list[$j]['filename'] == "") { |
2480 if ($p_filedescr_list[$j]['filename'] == "") { |
2684 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Skip empty filename"); |
|
2685 continue; |
2481 continue; |
2686 } |
2482 } |
2687 |
2483 |
2688 // ----- Check the filename |
2484 // ----- Check the filename |
2689 if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') |
2485 if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') |
2690 && (!file_exists($p_filedescr_list[$j]['filename']))) { |
2486 && (!file_exists($p_filedescr_list[$j]['filename']))) { |
2691 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); |
|
2692 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); |
2487 PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); |
2693 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2694 return PclZip::errorCode(); |
2488 return PclZip::errorCode(); |
2695 } |
2489 } |
2696 |
2490 |
2697 // ----- Look if it is a file or a dir with no all path remove option |
2491 // ----- Look if it is a file or a dir with no all path remove option |
2698 // or a dir with all its path removed |
2492 // or a dir with all its path removed |
2865 if ($p_header['status'] == 'ok') { |
2647 if ($p_header['status'] == 'ok') { |
2866 |
2648 |
2867 // ----- Look for a file |
2649 // ----- Look for a file |
2868 if ($p_filedescr['type'] == 'file') { |
2650 if ($p_filedescr['type'] == 'file') { |
2869 // ----- Look for using temporary file to zip |
2651 // ----- Look for using temporary file to zip |
2870 if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
2652 if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
2871 && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
2653 && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
2872 || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
2654 || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
2873 && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { |
2655 && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { |
2874 $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); |
2656 $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); |
2875 if ($v_result < PCLZIP_ERR_NO_ERROR) { |
2657 if ($v_result < PCLZIP_ERR_NO_ERROR) { |
2876 return $v_result; |
2658 return $v_result; |
2877 } |
2659 } |
2878 } |
2660 } |
2879 |
2661 |
2880 // ----- Use "in memory" zip algo |
2662 // ----- Use "in memory" zip algo |
2881 else { |
2663 else { |
2882 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2,"In memory compression."); |
|
2883 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2,"Current memory usage : ".memory_get_usage(TRUE)." bytes"); |
|
2884 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2,"Current memory peak : ".memory_get_peak_usage(TRUE)." bytes"); |
|
2885 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file"); |
|
2886 |
2664 |
2887 // ----- Open the source file |
2665 // ----- Open the source file |
2888 if (($v_file = @fopen($p_filename, "rb")) == 0) { |
2666 if (($v_file = @fopen($p_filename, "rb")) == 0) { |
2889 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
2667 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
2890 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
2891 return PclZip::errorCode(); |
2668 return PclZip::errorCode(); |
2892 } |
2669 } |
2893 |
2670 |
2894 // ----- Read the file content |
2671 // ----- Read the file content |
2895 $v_content = @fread($v_file, $p_header['size']); |
2672 $v_content = @fread($v_file, $p_header['size']); |
2896 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2,"Memory usage after reading file : ".memory_get_usage(TRUE)." bytes"); |
|
2897 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2,"Memory peak after reading file : ".memory_get_peak_usage(TRUE)." bytes"); |
|
2898 |
2673 |
2899 // ----- Close the file |
2674 // ----- Close the file |
2900 @fclose($v_file); |
2675 @fclose($v_file); |
2901 |
2676 |
2902 // ----- Calculate the CRC |
2677 // ----- Calculate the CRC |
2903 $p_header['crc'] = @crc32($v_content); |
2678 $p_header['crc'] = @crc32($v_content); |
2904 |
2679 |
2905 // ----- Look for no compression |
2680 // ----- Look for no compression |
2906 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { |
2681 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { |
2907 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed"); |
|
2908 // ----- Set header parameters |
2682 // ----- Set header parameters |
2909 $p_header['compressed_size'] = $p_header['size']; |
2683 $p_header['compressed_size'] = $p_header['size']; |
2910 $p_header['compression'] = 0; |
2684 $p_header['compression'] = 0; |
2911 } |
2685 } |
2912 |
2686 |
2913 // ----- Look for normal compression |
2687 // ----- Look for normal compression |
2914 else { |
2688 else { |
2915 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed"); |
|
2916 // ----- Compress the content |
2689 // ----- Compress the content |
2917 $v_content = @gzdeflate($v_content); |
2690 $v_content = @gzdeflate($v_content); |
2918 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2,"Memory usage after gzdeflate : ".memory_get_usage(TRUE)." bytes"); |
|
2919 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2,"Memory peak after gzdeflate : ".memory_get_peak_usage(TRUE)." bytes"); |
|
2920 |
2691 |
2921 // ----- Set header parameters |
2692 // ----- Set header parameters |
2922 $p_header['compressed_size'] = strlen($v_content); |
2693 $p_header['compressed_size'] = strlen($v_content); |
2923 $p_header['compression'] = 8; |
2694 $p_header['compression'] = 8; |
2924 } |
2695 } |
2925 |
2696 |
2926 // ----- Call the header generation |
2697 // ----- Call the header generation |
2927 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
2698 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
2928 @fclose($v_file); |
2699 @fclose($v_file); |
2929 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2930 return $v_result; |
2700 return $v_result; |
2931 } |
2701 } |
2932 |
2702 |
2933 // ----- Write the compressed (or not) content |
2703 // ----- Write the compressed (or not) content |
2934 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); |
2704 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); |
2937 |
2707 |
2938 } |
2708 } |
2939 |
2709 |
2940 // ----- Look for a virtual file (a file from string) |
2710 // ----- Look for a virtual file (a file from string) |
2941 else if ($p_filedescr['type'] == 'virtual_file') { |
2711 else if ($p_filedescr['type'] == 'virtual_file') { |
2942 |
2712 |
2943 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Add by string"); |
|
2944 $v_content = $p_filedescr['content']; |
2713 $v_content = $p_filedescr['content']; |
2945 |
2714 |
2946 // ----- Calculate the CRC |
2715 // ----- Calculate the CRC |
2947 $p_header['crc'] = @crc32($v_content); |
2716 $p_header['crc'] = @crc32($v_content); |
2948 |
2717 |
2949 // ----- Look for no compression |
2718 // ----- Look for no compression |
2950 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { |
2719 if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { |
2951 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed"); |
|
2952 // ----- Set header parameters |
2720 // ----- Set header parameters |
2953 $p_header['compressed_size'] = $p_header['size']; |
2721 $p_header['compressed_size'] = $p_header['size']; |
2954 $p_header['compression'] = 0; |
2722 $p_header['compression'] = 0; |
2955 } |
2723 } |
2956 |
2724 |
2957 // ----- Look for normal compression |
2725 // ----- Look for normal compression |
2958 else { |
2726 else { |
2959 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed"); |
|
2960 // ----- Compress the content |
2727 // ----- Compress the content |
2961 $v_content = @gzdeflate($v_content); |
2728 $v_content = @gzdeflate($v_content); |
2962 |
2729 |
2963 // ----- Set header parameters |
2730 // ----- Set header parameters |
2964 $p_header['compressed_size'] = strlen($v_content); |
2731 $p_header['compressed_size'] = strlen($v_content); |
2965 $p_header['compression'] = 8; |
2732 $p_header['compression'] = 8; |
2966 } |
2733 } |
2967 |
2734 |
2968 // ----- Call the header generation |
2735 // ----- Call the header generation |
2969 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
2736 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
2970 @fclose($v_file); |
2737 @fclose($v_file); |
2971 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
2972 return $v_result; |
2738 return $v_result; |
2973 } |
2739 } |
2974 |
2740 |
2975 // ----- Write the compressed (or not) content |
2741 // ----- Write the compressed (or not) content |
2976 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); |
2742 @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); |
2977 } |
2743 } |
2978 |
2744 |
2979 // ----- Look for a directory |
2745 // ----- Look for a directory |
2980 else if ($p_filedescr['type'] == 'folder') { |
2746 else if ($p_filedescr['type'] == 'folder') { |
2981 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder"); |
|
2982 // ----- Look for directory last '/' |
2747 // ----- Look for directory last '/' |
2983 if (@substr($p_header['stored_filename'], -1) != '/') { |
2748 if (@substr($p_header['stored_filename'], -1) != '/') { |
2984 $p_header['stored_filename'] .= '/'; |
2749 $p_header['stored_filename'] .= '/'; |
2985 } |
2750 } |
2986 |
2751 |
3031 // Parameters : |
2793 // Parameters : |
3032 // Return Values : |
2794 // Return Values : |
3033 // -------------------------------------------------------------------------------- |
2795 // -------------------------------------------------------------------------------- |
3034 function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) |
2796 function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) |
3035 { |
2797 { |
3036 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileUsingTempFile", "filename='".$p_filedescr['filename']."'"); |
|
3037 $v_result=PCLZIP_ERR_NO_ERROR; |
2798 $v_result=PCLZIP_ERR_NO_ERROR; |
3038 |
2799 |
3039 // ----- Working variable |
2800 // ----- Working variable |
3040 $p_filename = $p_filedescr['filename']; |
2801 $p_filename = $p_filedescr['filename']; |
3041 |
2802 |
3042 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file"); |
|
3043 |
2803 |
3044 // ----- Open the source file |
2804 // ----- Open the source file |
3045 if (($v_file = @fopen($p_filename, "rb")) == 0) { |
2805 if (($v_file = @fopen($p_filename, "rb")) == 0) { |
3046 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
2806 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
3047 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
3048 return PclZip::errorCode(); |
2807 return PclZip::errorCode(); |
3049 } |
2808 } |
3050 |
2809 |
3051 // ----- Creates a compressed temporary file |
2810 // ----- Creates a compressed temporary file |
3052 $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
2811 $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
3053 if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { |
2812 if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { |
3054 fclose($v_file); |
2813 fclose($v_file); |
3055 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
2814 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
3056 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
3057 return PclZip::errorCode(); |
2815 return PclZip::errorCode(); |
3058 } |
2816 } |
3059 |
2817 |
3060 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
2818 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
3061 $v_size = filesize($p_filename); |
2819 $v_size = filesize($p_filename); |
3062 while ($v_size != 0) { |
2820 while ($v_size != 0) { |
3063 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
2821 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
3064 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read ".$v_read_size." bytes"); |
|
3065 $v_buffer = @fread($v_file, $v_read_size); |
2822 $v_buffer = @fread($v_file, $v_read_size); |
3066 //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
2823 //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
3067 @gzputs($v_file_compressed, $v_buffer, $v_read_size); |
2824 @gzputs($v_file_compressed, $v_buffer, $v_read_size); |
3068 $v_size -= $v_read_size; |
2825 $v_size -= $v_read_size; |
3069 } |
2826 } |
3071 // ----- Close the file |
2828 // ----- Close the file |
3072 @fclose($v_file); |
2829 @fclose($v_file); |
3073 @gzclose($v_file_compressed); |
2830 @gzclose($v_file_compressed); |
3074 |
2831 |
3075 // ----- Check the minimum file size |
2832 // ----- Check the minimum file size |
3076 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "gzip file size ".filesize($v_gzip_temp_name)); |
|
3077 if (filesize($v_gzip_temp_name) < 18) { |
2833 if (filesize($v_gzip_temp_name) < 18) { |
3078 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); |
2834 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); |
3079 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
3080 return PclZip::errorCode(); |
2835 return PclZip::errorCode(); |
3081 } |
2836 } |
3082 |
2837 |
3083 // ----- Extract the compressed attributes |
2838 // ----- Extract the compressed attributes |
3084 if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { |
2839 if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { |
3085 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
2840 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
3086 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
3087 return PclZip::errorCode(); |
2841 return PclZip::errorCode(); |
3088 } |
2842 } |
3089 |
2843 |
3090 // ----- Read the gzip file header |
2844 // ----- Read the gzip file header |
3091 $v_binary_data = @fread($v_file_compressed, 10); |
2845 $v_binary_data = @fread($v_file_compressed, 10); |
3092 $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data); |
2846 $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data); |
3093 |
2847 |
3094 // ----- Check some parameters |
2848 // ----- Check some parameters |
3095 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[id1]='.bin2hex($v_data_header['id1'])); |
|
3096 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[id2]='.bin2hex($v_data_header['id2'])); |
|
3097 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[cm]='.bin2hex($v_data_header['cm'])); |
|
3098 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[flag]='.bin2hex($v_data_header['flag'])); |
|
3099 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[mtime]='.$v_data_header['mtime']); |
|
3100 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[xfl]='.bin2hex($v_data_header['xfl'])); |
|
3101 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, '$v_data_header[os]='.bin2hex($v_data_header['os'])); |
|
3102 $v_data_header['os'] = bin2hex($v_data_header['os']); |
2849 $v_data_header['os'] = bin2hex($v_data_header['os']); |
3103 |
2850 |
3104 // ----- Read the gzip file footer |
2851 // ----- Read the gzip file footer |
3105 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position after header ".ftell($v_file_compressed)); |
|
3106 @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8); |
2852 @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8); |
3107 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position at beginning of footer ".ftell($v_file_compressed)); |
|
3108 $v_binary_data = @fread($v_file_compressed, 8); |
2853 $v_binary_data = @fread($v_file_compressed, 8); |
3109 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position after footer ".ftell($v_file_compressed)); |
|
3110 $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data); |
2854 $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data); |
3111 |
2855 |
3112 // ----- Set the attributes |
2856 // ----- Set the attributes |
3113 $p_header['compression'] = ord($v_data_header['cm']); |
2857 $p_header['compression'] = ord($v_data_header['cm']); |
3114 //$p_header['mtime'] = $v_data_header['mtime']; |
2858 //$p_header['mtime'] = $v_data_header['mtime']; |
3115 $p_header['crc'] = $v_data_footer['crc']; |
2859 $p_header['crc'] = $v_data_footer['crc']; |
3116 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Compressed size ".(filesize($v_gzip_temp_name)-18)); |
|
3117 $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18; |
2860 $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18; |
3118 |
2861 |
3119 // ----- Close the file |
2862 // ----- Close the file |
3120 @fclose($v_file_compressed); |
2863 @fclose($v_file_compressed); |
3121 |
2864 |
3122 // ----- Call the header generation |
2865 // ----- Call the header generation |
3123 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
2866 if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
3124 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
3125 return $v_result; |
2867 return $v_result; |
3126 } |
2868 } |
3127 |
2869 |
3128 // ----- Add the compressed data |
2870 // ----- Add the compressed data |
3129 if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) |
2871 if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) |
3130 { |
2872 { |
3131 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
2873 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
3132 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
3133 return PclZip::errorCode(); |
2874 return PclZip::errorCode(); |
3134 } |
2875 } |
3135 |
2876 |
3136 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
2877 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
3137 fseek($v_file_compressed, 10); |
2878 fseek($v_file_compressed, 10); |
3138 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File position before reading compressed data ".ftell($v_file_compressed)); |
|
3139 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, ' '.$p_header['compressed_size'].' bytes to read'); |
|
3140 $v_size = $p_header['compressed_size']; |
2879 $v_size = $p_header['compressed_size']; |
3141 while ($v_size != 0) |
2880 while ($v_size != 0) |
3142 { |
2881 { |
3143 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
2882 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
3144 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read ".$v_read_size." bytes"); |
|
3145 $v_buffer = @fread($v_file_compressed, $v_read_size); |
2883 $v_buffer = @fread($v_file_compressed, $v_read_size); |
3146 //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
2884 //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
3147 @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
2885 @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
3148 $v_size -= $v_read_size; |
2886 $v_size -= $v_read_size; |
3149 } |
2887 } |
3429 // Parameters : |
3144 // Parameters : |
3430 // Return Values : |
3145 // Return Values : |
3431 // -------------------------------------------------------------------------------- |
3146 // -------------------------------------------------------------------------------- |
3432 function privList(&$p_list) |
3147 function privList(&$p_list) |
3433 { |
3148 { |
3434 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privList", "list"); |
|
3435 $v_result=1; |
3149 $v_result=1; |
3436 |
3150 |
3437 // ----- Magic quotes trick |
3151 // ----- Magic quotes trick |
3438 $this->privDisableMagicQuotes(); |
3152 $this->privDisableMagicQuotes(); |
3439 |
3153 |
3440 // ----- Open the zip file |
3154 // ----- Open the zip file |
3441 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); |
|
3442 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) |
3155 if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) |
3443 { |
3156 { |
3444 // ----- Magic quotes trick |
3157 // ----- Magic quotes trick |
3445 $this->privSwapBackMagicQuotes(); |
3158 $this->privSwapBackMagicQuotes(); |
3446 |
3159 |
3447 // ----- Error log |
3160 // ----- Error log |
3448 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
3161 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
3449 |
3162 |
3450 // ----- Return |
3163 // ----- Return |
3451 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
3452 return PclZip::errorCode(); |
3164 return PclZip::errorCode(); |
3453 } |
3165 } |
3454 |
3166 |
3455 // ----- Read the central directory informations |
3167 // ----- Read the central directory informations |
3456 $v_central_dir = array(); |
3168 $v_central_dir = array(); |
3457 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
3169 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
3458 { |
3170 { |
3459 $this->privSwapBackMagicQuotes(); |
3171 $this->privSwapBackMagicQuotes(); |
3460 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
3461 return $v_result; |
3172 return $v_result; |
3462 } |
3173 } |
3463 |
3174 |
3464 // ----- Go to beginning of Central Dir |
3175 // ----- Go to beginning of Central Dir |
3465 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Offset : ".$v_central_dir['offset']."'"); |
|
3466 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); |
|
3467 @rewind($this->zip_fd); |
3176 @rewind($this->zip_fd); |
3468 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); |
|
3469 if (@fseek($this->zip_fd, $v_central_dir['offset'])) |
3177 if (@fseek($this->zip_fd, $v_central_dir['offset'])) |
3470 { |
3178 { |
3471 $this->privSwapBackMagicQuotes(); |
3179 $this->privSwapBackMagicQuotes(); |
3472 |
3180 |
3473 // ----- Error log |
3181 // ----- Error log |
3474 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
3182 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
3475 |
3183 |
3476 // ----- Return |
3184 // ----- Return |
3477 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
3478 return PclZip::errorCode(); |
3185 return PclZip::errorCode(); |
3479 } |
3186 } |
3480 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); |
|
3481 |
3187 |
3482 // ----- Read each entry |
3188 // ----- Read each entry |
3483 for ($i=0; $i<$v_central_dir['entries']; $i++) |
3189 for ($i=0; $i<$v_central_dir['entries']; $i++) |
3484 { |
3190 { |
3485 // ----- Read the file header |
3191 // ----- Read the file header |
3486 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
3192 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
3487 { |
3193 { |
3488 $this->privSwapBackMagicQuotes(); |
3194 $this->privSwapBackMagicQuotes(); |
3489 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
3490 return $v_result; |
3195 return $v_result; |
3491 } |
3196 } |
3492 $v_header['index'] = $i; |
3197 $v_header['index'] = $i; |
3493 |
3198 |
3494 // ----- Get the only interesting attributes |
3199 // ----- Get the only interesting attributes |
3617 { |
3314 { |
3618 // ----- Close the zip file |
3315 // ----- Close the zip file |
3619 $this->privCloseFd(); |
3316 $this->privCloseFd(); |
3620 $this->privSwapBackMagicQuotes(); |
3317 $this->privSwapBackMagicQuotes(); |
3621 |
3318 |
3622 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
3623 return $v_result; |
3319 return $v_result; |
3624 } |
3320 } |
3625 |
3321 |
3626 // ----- Start at beginning of Central Dir |
3322 // ----- Start at beginning of Central Dir |
3627 $v_pos_entry = $v_central_dir['offset']; |
3323 $v_pos_entry = $v_central_dir['offset']; |
3628 |
3324 |
3629 // ----- Read each entry |
3325 // ----- Read each entry |
3630 $j_start = 0; |
3326 $j_start = 0; |
3631 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
3327 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
3632 { |
3328 { |
3633 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry : '$i'"); |
|
3634 |
3329 |
3635 // ----- Read next Central dir entry |
3330 // ----- Read next Central dir entry |
3636 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position before rewind : ".ftell($this->zip_fd)."'"); |
|
3637 @rewind($this->zip_fd); |
3331 @rewind($this->zip_fd); |
3638 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position after rewind : ".ftell($this->zip_fd)."'"); |
|
3639 if (@fseek($this->zip_fd, $v_pos_entry)) |
3332 if (@fseek($this->zip_fd, $v_pos_entry)) |
3640 { |
3333 { |
3641 // ----- Close the zip file |
3334 // ----- Close the zip file |
3642 $this->privCloseFd(); |
3335 $this->privCloseFd(); |
3643 $this->privSwapBackMagicQuotes(); |
3336 $this->privSwapBackMagicQuotes(); |
3644 |
3337 |
3645 // ----- Error log |
3338 // ----- Error log |
3646 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
3339 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
3647 |
3340 |
3648 // ----- Return |
3341 // ----- Return |
3649 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
3650 return PclZip::errorCode(); |
3342 return PclZip::errorCode(); |
3651 } |
3343 } |
3652 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position after fseek : ".ftell($this->zip_fd)."'"); |
|
3653 |
3344 |
3654 // ----- Read the file header |
3345 // ----- Read the file header |
3655 $v_header = array(); |
3346 $v_header = array(); |
3656 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
3347 if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
3657 { |
3348 { |
3658 // ----- Close the zip file |
3349 // ----- Close the zip file |
3659 $this->privCloseFd(); |
3350 $this->privCloseFd(); |
3660 $this->privSwapBackMagicQuotes(); |
3351 $this->privSwapBackMagicQuotes(); |
3661 |
3352 |
3662 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
3663 return $v_result; |
3353 return $v_result; |
3664 } |
3354 } |
3665 |
3355 |
3666 // ----- Store the index |
3356 // ----- Store the index |
3667 $v_header['index'] = $i; |
3357 $v_header['index'] = $i; |
3673 $v_extract = false; |
3363 $v_extract = false; |
3674 |
3364 |
3675 // ----- Look for extract by name rule |
3365 // ----- Look for extract by name rule |
3676 if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
3366 if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
3677 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
3367 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
3678 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'"); |
|
3679 |
3368 |
3680 // ----- Look if the filename is in the list |
3369 // ----- Look if the filename is in the list |
3681 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { |
3370 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { |
3682 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'"); |
|
3683 |
3371 |
3684 // ----- Look for a directory |
3372 // ----- Look for a directory |
3685 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
3373 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
3686 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory"); |
|
3687 |
3374 |
3688 // ----- Look if the directory is in the filename path |
3375 // ----- Look if the directory is in the filename path |
3689 if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
3376 if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
3690 && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
3377 && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
3691 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path"); |
|
3692 $v_extract = true; |
3378 $v_extract = true; |
3693 } |
3379 } |
3694 } |
3380 } |
3695 // ----- Look for a filename |
3381 // ----- Look for a filename |
3696 elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
3382 elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
3697 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one."); |
|
3698 $v_extract = true; |
3383 $v_extract = true; |
3699 } |
3384 } |
3700 } |
3385 } |
3701 } |
3386 } |
3702 |
3387 |
3703 // ----- Look for extract by ereg rule |
3388 // ----- Look for extract by ereg rule |
|
3389 // ereg() is deprecated with PHP 5.3 |
|
3390 /* |
3704 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) |
3391 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) |
3705 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { |
3392 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { |
3706 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'"); |
|
3707 |
3393 |
3708 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) { |
3394 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) { |
3709 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); |
|
3710 $v_extract = true; |
3395 $v_extract = true; |
3711 } |
3396 } |
3712 } |
3397 } |
|
3398 */ |
3713 |
3399 |
3714 // ----- Look for extract by preg rule |
3400 // ----- Look for extract by preg rule |
3715 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
3401 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
3716 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
3402 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
3717 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'"); |
|
3718 |
3403 |
3719 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { |
3404 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { |
3720 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); |
|
3721 $v_extract = true; |
3405 $v_extract = true; |
3722 } |
3406 } |
3723 } |
3407 } |
3724 |
3408 |
3725 // ----- Look for extract by index rule |
3409 // ----- Look for extract by index rule |
3726 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
3410 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
3727 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
3411 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
3728 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'"); |
3412 |
3729 |
|
3730 // ----- Look if the index is in the list |
3413 // ----- Look if the index is in the list |
3731 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { |
3414 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { |
3732 //--(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']."]"); |
|
3733 |
3415 |
3734 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
3416 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
3735 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range"); |
|
3736 $v_extract = true; |
3417 $v_extract = true; |
3737 } |
3418 } |
3738 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
3419 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
3739 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop"); |
|
3740 $j_start = $j+1; |
3420 $j_start = $j+1; |
3741 } |
3421 } |
3742 |
3422 |
3743 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
3423 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
3744 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop"); |
|
3745 break; |
3424 break; |
3746 } |
3425 } |
3747 } |
3426 } |
3748 } |
3427 } |
3749 |
3428 |
3750 // ----- Look for no rule, which means extract all the archive |
3429 // ----- Look for no rule, which means extract all the archive |
3751 else { |
3430 else { |
3752 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with no rule (extract all)"); |
|
3753 $v_extract = true; |
3431 $v_extract = true; |
3754 } |
3432 } |
3755 |
3433 |
3756 // ----- Check compression method |
3434 // ----- Check compression method |
3757 if ( ($v_extract) |
3435 if ( ($v_extract) |
3758 && ( ($v_header['compression'] != 8) |
3436 && ( ($v_header['compression'] != 8) |
3759 && ($v_header['compression'] != 0))) { |
3437 && ($v_header['compression'] != 0))) { |
3760 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported compression method (".$v_header['compression'].")"); |
|
3761 $v_header['status'] = 'unsupported_compression'; |
3438 $v_header['status'] = 'unsupported_compression'; |
3762 |
3439 |
3763 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
3440 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
3764 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
3441 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
3765 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
3442 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
3766 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); |
|
3767 |
3443 |
3768 $this->privSwapBackMagicQuotes(); |
3444 $this->privSwapBackMagicQuotes(); |
3769 |
3445 |
3770 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, |
3446 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, |
3771 "Filename '".$v_header['stored_filename']."' is " |
3447 "Filename '".$v_header['stored_filename']."' is " |
3772 ."compressed by an unsupported compression " |
3448 ."compressed by an unsupported compression " |
3773 ."method (".$v_header['compression'].") "); |
3449 ."method (".$v_header['compression'].") "); |
3774 |
3450 |
3775 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
3776 return PclZip::errorCode(); |
3451 return PclZip::errorCode(); |
3777 } |
3452 } |
3778 } |
3453 } |
3779 |
3454 |
3780 // ----- Check encrypted files |
3455 // ----- Check encrypted files |
3781 if (($v_extract) && (($v_header['flag'] & 1) == 1)) { |
3456 if (($v_extract) && (($v_header['flag'] & 1) == 1)) { |
3782 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported file encryption"); |
|
3783 $v_header['status'] = 'unsupported_encryption'; |
3457 $v_header['status'] = 'unsupported_encryption'; |
3784 |
3458 |
3785 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
3459 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
3786 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
3460 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
3787 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
3461 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
3788 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); |
|
3789 |
3462 |
3790 $this->privSwapBackMagicQuotes(); |
3463 $this->privSwapBackMagicQuotes(); |
3791 |
3464 |
3792 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, |
3465 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, |
3793 "Unsupported encryption for " |
3466 "Unsupported encryption for " |
3794 ." filename '".$v_header['stored_filename'] |
3467 ." filename '".$v_header['stored_filename'] |
3795 ."'"); |
3468 ."'"); |
3796 |
3469 |
3797 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
3798 return PclZip::errorCode(); |
3470 return PclZip::errorCode(); |
3799 } |
3471 } |
3800 } |
3472 } |
3801 |
3473 |
3802 // ----- Look for real extraction |
3474 // ----- Look for real extraction |
3803 if (($v_extract) && ($v_header['status'] != 'ok')) { |
3475 if (($v_extract) && ($v_header['status'] != 'ok')) { |
3804 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "No need for extract"); |
|
3805 $v_result = $this->privConvertHeader2FileInfo($v_header, |
3476 $v_result = $this->privConvertHeader2FileInfo($v_header, |
3806 $p_file_list[$v_nb_extracted++]); |
3477 $p_file_list[$v_nb_extracted++]); |
3807 if ($v_result != 1) { |
3478 if ($v_result != 1) { |
3808 $this->privCloseFd(); |
3479 $this->privCloseFd(); |
3809 $this->privSwapBackMagicQuotes(); |
3480 $this->privSwapBackMagicQuotes(); |
3810 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
3811 return $v_result; |
3481 return $v_result; |
3812 } |
3482 } |
3813 |
3483 |
3814 $v_extract = false; |
3484 $v_extract = false; |
3815 } |
3485 } |
3816 |
3486 |
3817 // ----- Look for real extraction |
3487 // ----- Look for real extraction |
3818 if ($v_extract) |
3488 if ($v_extract) |
3819 { |
3489 { |
3820 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file '".$v_header['filename']."', index '$i'"); |
|
3821 |
3490 |
3822 // ----- Go to the file position |
3491 // ----- Go to the file position |
3823 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); |
|
3824 @rewind($this->zip_fd); |
3492 @rewind($this->zip_fd); |
3825 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); |
|
3826 if (@fseek($this->zip_fd, $v_header['offset'])) |
3493 if (@fseek($this->zip_fd, $v_header['offset'])) |
3827 { |
3494 { |
3828 // ----- Close the zip file |
3495 // ----- Close the zip file |
3829 $this->privCloseFd(); |
3496 $this->privCloseFd(); |
3830 |
3497 |
3950 // 1 : ... ? |
3610 // 1 : ... ? |
3951 // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback |
3611 // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback |
3952 // -------------------------------------------------------------------------------- |
3612 // -------------------------------------------------------------------------------- |
3953 function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
3613 function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
3954 { |
3614 { |
3955 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'"); |
|
3956 $v_result=1; |
3615 $v_result=1; |
3957 |
3616 |
3958 // ----- Read the file header |
3617 // ----- Read the file header |
3959 if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
3618 if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
3960 { |
3619 { |
3961 // ----- Return |
3620 // ----- Return |
3962 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
3963 return $v_result; |
3621 return $v_result; |
3964 } |
3622 } |
3965 |
3623 |
3966 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); |
|
3967 |
3624 |
3968 // ----- Check that the file header is coherent with $p_entry info |
3625 // ----- Check that the file header is coherent with $p_entry info |
3969 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
3626 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
3970 // TBC |
3627 // TBC |
3971 } |
3628 } |
3972 |
3629 |
3973 // ----- Look for all path to remove |
3630 // ----- Look for all path to remove |
3974 if ($p_remove_all_path == true) { |
3631 if ($p_remove_all_path == true) { |
3975 // ----- Look for folder entry that not need to be extracted |
3632 // ----- Look for folder entry that not need to be extracted |
3976 if (($p_entry['external']&0x00000010)==0x00000010) { |
3633 if (($p_entry['external']&0x00000010)==0x00000010) { |
3977 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The entry is a folder : need to be filtered"); |
|
3978 |
3634 |
3979 $p_entry['status'] = "filtered"; |
3635 $p_entry['status'] = "filtered"; |
3980 |
3636 |
3981 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
3982 return $v_result; |
3637 return $v_result; |
3983 } |
3638 } |
3984 |
3639 |
3985 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "All path is removed"); |
|
3986 // ----- Get the basename of the path |
3640 // ----- Get the basename of the path |
3987 $p_entry['filename'] = basename($p_entry['filename']); |
3641 $p_entry['filename'] = basename($p_entry['filename']); |
3988 } |
3642 } |
3989 |
3643 |
3990 // ----- Look for path to remove |
3644 // ----- Look for path to remove |
3991 else if ($p_remove_path != "") |
3645 else if ($p_remove_path != "") |
3992 { |
3646 { |
3993 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look for some path to remove"); |
|
3994 if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) |
3647 if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) |
3995 { |
3648 { |
3996 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '".$p_entry['filename']."'"); |
|
3997 |
3649 |
3998 // ----- Change the file status |
3650 // ----- Change the file status |
3999 $p_entry['status'] = "filtered"; |
3651 $p_entry['status'] = "filtered"; |
4000 |
3652 |
4001 // ----- Return |
3653 // ----- Return |
4002 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
4003 return $v_result; |
3654 return $v_result; |
4004 } |
3655 } |
4005 |
3656 |
4006 $p_remove_path_size = strlen($p_remove_path); |
3657 $p_remove_path_size = strlen($p_remove_path); |
4007 if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) |
3658 if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) |
4008 { |
3659 { |
4009 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '".$p_entry['filename']."'"); |
|
4010 |
3660 |
4011 // ----- Remove the path |
3661 // ----- Remove the path |
4012 $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); |
3662 $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); |
4013 |
3663 |
4014 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '".$p_entry['filename']."'"); |
|
4015 } |
3664 } |
4016 } |
3665 } |
4017 |
3666 |
4018 // ----- Add the path |
3667 // ----- Add the path |
4019 if ($p_path != '') { |
3668 if ($p_path != '') { |
4020 $p_entry['filename'] = $p_path."/".$p_entry['filename']; |
3669 $p_entry['filename'] = $p_path."/".$p_entry['filename']; |
4021 } |
3670 } |
4022 |
3671 |
4023 // ----- Check a base_dir_restriction |
3672 // ----- Check a base_dir_restriction |
4024 if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { |
3673 if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { |
4025 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Check the extract directory restriction"); |
|
4026 $v_inclusion |
3674 $v_inclusion |
4027 = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], |
3675 = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], |
4028 $p_entry['filename']); |
3676 $p_entry['filename']); |
4029 if ($v_inclusion == 0) { |
3677 if ($v_inclusion == 0) { |
4030 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction"); |
|
4031 |
3678 |
4032 PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, |
3679 PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, |
4033 "Filename '".$p_entry['filename']."' is " |
3680 "Filename '".$p_entry['filename']."' is " |
4034 ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); |
3681 ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); |
4035 |
3682 |
4036 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
4037 return PclZip::errorCode(); |
3683 return PclZip::errorCode(); |
4038 } |
3684 } |
4039 } |
3685 } |
4040 |
3686 |
4041 // ----- Look for pre-extract callback |
3687 // ----- Look for pre-extract callback |
4042 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
3688 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
4043 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction"); |
|
4044 |
3689 |
4045 // ----- Generate a local information |
3690 // ----- Generate a local information |
4046 $v_local_header = array(); |
3691 $v_local_header = array(); |
4047 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
3692 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
4048 |
3693 |
4049 // ----- Call the callback |
3694 // ----- Call the callback |
4050 // Here I do not use call_user_func() because I need to send a reference to the |
3695 // Here I do not use call_user_func() because I need to send a reference to the |
4051 // header. |
3696 // header. |
4052 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); |
3697 $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
4053 if ($v_result == 0) { |
3698 if ($v_result == 0) { |
4054 // ----- Change the file status |
3699 // ----- Change the file status |
4055 $p_entry['status'] = "skipped"; |
3700 $p_entry['status'] = "skipped"; |
4056 $v_result = 1; |
3701 $v_result = 1; |
4057 } |
3702 } |
4058 |
3703 |
4059 // ----- Look for abort result |
3704 // ----- Look for abort result |
4060 if ($v_result == 2) { |
3705 if ($v_result == 2) { |
4061 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); |
|
4062 // ----- This status is internal and will be changed in 'skipped' |
3706 // ----- This status is internal and will be changed in 'skipped' |
4063 $p_entry['status'] = "aborted"; |
3707 $p_entry['status'] = "aborted"; |
4064 $v_result = PCLZIP_ERR_USER_ABORTED; |
3708 $v_result = PCLZIP_ERR_USER_ABORTED; |
4065 } |
3709 } |
4066 |
3710 |
4067 // ----- Update the informations |
3711 // ----- Update the informations |
4068 // Only some fields can be modified |
3712 // Only some fields can be modified |
4069 $p_entry['filename'] = $v_local_header['filename']; |
3713 $p_entry['filename'] = $v_local_header['filename']; |
4070 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'"); |
3714 } |
4071 } |
3715 |
4072 |
|
4073 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'"); |
|
4074 |
3716 |
4075 // ----- Look if extraction should be done |
3717 // ----- Look if extraction should be done |
4076 if ($p_entry['status'] == 'ok') { |
3718 if ($p_entry['status'] == 'ok') { |
4077 |
3719 |
4078 // ----- Look for specific actions while the file exist |
3720 // ----- Look for specific actions while the file exist |
4079 if (file_exists($p_entry['filename'])) |
3721 if (file_exists($p_entry['filename'])) |
4080 { |
3722 { |
4081 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_entry['filename']."' already exists"); |
|
4082 |
3723 |
4083 // ----- Look if file is a directory |
3724 // ----- Look if file is a directory |
4084 if (is_dir($p_entry['filename'])) |
3725 if (is_dir($p_entry['filename'])) |
4085 { |
3726 { |
4086 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is a directory"); |
|
4087 |
3727 |
4088 // ----- Change the file status |
3728 // ----- Change the file status |
4089 $p_entry['status'] = "already_a_directory"; |
3729 $p_entry['status'] = "already_a_directory"; |
4090 |
3730 |
4091 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
3731 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
4092 // For historical reason first PclZip implementation does not stop |
3732 // For historical reason first PclZip implementation does not stop |
4093 // when this kind of error occurs. |
3733 // when this kind of error occurs. |
4094 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
3734 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
4095 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
3735 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
4096 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); |
|
4097 |
3736 |
4098 PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, |
3737 PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, |
4099 "Filename '".$p_entry['filename']."' is " |
3738 "Filename '".$p_entry['filename']."' is " |
4100 ."already used by an existing directory"); |
3739 ."already used by an existing directory"); |
4101 |
3740 |
4102 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
4103 return PclZip::errorCode(); |
3741 return PclZip::errorCode(); |
4104 } |
3742 } |
4105 } |
3743 } |
4106 // ----- Look if file is write protected |
3744 // ----- Look if file is write protected |
4107 else if (!is_writeable($p_entry['filename'])) |
3745 else if (!is_writeable($p_entry['filename'])) |
4108 { |
3746 { |
4109 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is write protected"); |
|
4110 |
3747 |
4111 // ----- Change the file status |
3748 // ----- Change the file status |
4112 $p_entry['status'] = "write_protected"; |
3749 $p_entry['status'] = "write_protected"; |
4113 |
3750 |
4114 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
3751 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
4115 // For historical reason first PclZip implementation does not stop |
3752 // For historical reason first PclZip implementation does not stop |
4116 // when this kind of error occurs. |
3753 // when this kind of error occurs. |
4117 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
3754 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
4118 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
3755 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
4119 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); |
|
4120 |
3756 |
4121 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
3757 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
4122 "Filename '".$p_entry['filename']."' exists " |
3758 "Filename '".$p_entry['filename']."' exists " |
4123 ."and is write protected"); |
3759 ."and is write protected"); |
4124 |
3760 |
4125 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
4126 return PclZip::errorCode(); |
3761 return PclZip::errorCode(); |
4127 } |
3762 } |
4128 } |
3763 } |
4129 |
3764 |
4130 // ----- Look if the extracted file is older |
3765 // ----- Look if the extracted file is older |
4131 else if (filemtime($p_entry['filename']) > $p_entry['mtime']) |
3766 else if (filemtime($p_entry['filename']) > $p_entry['mtime']) |
4132 { |
3767 { |
4133 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is newer (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")"); |
|
4134 // ----- Change the file status |
3768 // ----- Change the file status |
4135 if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) |
3769 if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) |
4136 && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { |
3770 && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { |
4137 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_REPLACE_NEWER is selected, file will be replaced"); |
|
4138 } |
3771 } |
4139 else { |
3772 else { |
4140 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be replaced"); |
|
4141 $p_entry['status'] = "newer_exist"; |
3773 $p_entry['status'] = "newer_exist"; |
4142 |
3774 |
4143 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
3775 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
4144 // For historical reason first PclZip implementation does not stop |
3776 // For historical reason first PclZip implementation does not stop |
4145 // when this kind of error occurs. |
3777 // when this kind of error occurs. |
4146 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
3778 if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
4147 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
3779 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
4148 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); |
|
4149 |
3780 |
4150 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
3781 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
4151 "Newer version of '".$p_entry['filename']."' exists " |
3782 "Newer version of '".$p_entry['filename']."' exists " |
4152 ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); |
3783 ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); |
4153 |
3784 |
4154 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
4155 return PclZip::errorCode(); |
3785 return PclZip::errorCode(); |
4156 } |
3786 } |
4157 } |
3787 } |
4158 } |
3788 } |
4159 else { |
3789 else { |
4160 //--(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']).")"); |
|
4161 } |
3790 } |
4162 } |
3791 } |
4163 |
3792 |
4164 // ----- Check the directory availability and create it if necessary |
3793 // ----- Check the directory availability and create it if necessary |
4165 else { |
3794 else { |
4190 // ----- Do the extraction (if not a folder) |
3817 // ----- Do the extraction (if not a folder) |
4191 if (!(($p_entry['external']&0x00000010)==0x00000010)) |
3818 if (!(($p_entry['external']&0x00000010)==0x00000010)) |
4192 { |
3819 { |
4193 // ----- Look for not compressed file |
3820 // ----- Look for not compressed file |
4194 if ($p_entry['compression'] == 0) { |
3821 if ($p_entry['compression'] == 0) { |
4195 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); |
|
4196 |
3822 |
4197 // ----- Opening destination file |
3823 // ----- Opening destination file |
4198 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) |
3824 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) |
4199 { |
3825 { |
4200 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); |
|
4201 |
3826 |
4202 // ----- Change the file status |
3827 // ----- Change the file status |
4203 $p_entry['status'] = "write_error"; |
3828 $p_entry['status'] = "write_error"; |
4204 |
3829 |
4205 // ----- Return |
3830 // ----- Return |
4206 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
4207 return $v_result; |
3831 return $v_result; |
4208 } |
3832 } |
4209 |
3833 |
4210 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read '".$p_entry['size']."' bytes"); |
|
4211 |
3834 |
4212 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
3835 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
4213 $v_size = $p_entry['compressed_size']; |
3836 $v_size = $p_entry['compressed_size']; |
4214 while ($v_size != 0) |
3837 while ($v_size != 0) |
4215 { |
3838 { |
4216 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
3839 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
4217 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes"); |
|
4218 $v_buffer = @fread($this->zip_fd, $v_read_size); |
3840 $v_buffer = @fread($this->zip_fd, $v_read_size); |
4219 /* Try to speed up the code |
3841 /* Try to speed up the code |
4220 $v_binary_data = pack('a'.$v_read_size, $v_buffer); |
3842 $v_binary_data = pack('a'.$v_read_size, $v_buffer); |
4221 @fwrite($v_dest_file, $v_binary_data, $v_read_size); |
3843 @fwrite($v_dest_file, $v_binary_data, $v_read_size); |
4222 */ |
3844 */ |
4223 @fwrite($v_dest_file, $v_buffer, $v_read_size); |
3845 @fwrite($v_dest_file, $v_buffer, $v_read_size); |
4224 $v_size -= $v_read_size; |
3846 $v_size -= $v_read_size; |
4225 } |
3847 } |
4226 |
3848 |
4227 // ----- Closing the destination file |
3849 // ----- Closing the destination file |
4228 fclose($v_dest_file); |
3850 fclose($v_dest_file); |
4229 |
3851 |
4230 // ----- Change the file mtime |
3852 // ----- Change the file mtime |
4231 touch($p_entry['filename'], $p_entry['mtime']); |
3853 touch($p_entry['filename'], $p_entry['mtime']); |
4232 |
3854 |
4233 |
3855 |
4234 } |
3856 } |
4235 else { |
3857 else { |
4236 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (Compression method ".$p_entry['compression'].")"); |
|
4237 // ----- TBC |
3858 // ----- TBC |
4238 // Need to be finished |
3859 // Need to be finished |
4239 if (($p_entry['flag'] & 1) == 1) { |
3860 if (($p_entry['flag'] & 1) == 1) { |
4240 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File is encrypted"); |
|
4241 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.'); |
3861 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.'); |
4242 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
4243 return PclZip::errorCode(); |
3862 return PclZip::errorCode(); |
4244 } |
3863 } |
4245 |
3864 |
4246 |
3865 |
4247 // ----- Look for using temporary file to unzip |
3866 // ----- Look for using temporary file to unzip |
4248 if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
3867 if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
4249 && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
3868 && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
4250 || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
3869 || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
4251 && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) { |
3870 && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) { |
4252 $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options); |
3871 $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options); |
4253 if ($v_result < PCLZIP_ERR_NO_ERROR) { |
3872 if ($v_result < PCLZIP_ERR_NO_ERROR) { |
4254 return $v_result; |
3873 return $v_result; |
4255 } |
3874 } |
4256 } |
3875 } |
4257 |
3876 |
4258 // ----- Look for extract in memory |
3877 // ----- Look for extract in memory |
4259 else { |
3878 else { |
4260 |
3879 |
4261 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".$p_entry['compressed_size']."' compressed bytes"); |
3880 |
4262 |
|
4263 // ----- Read the compressed file in a buffer (one shot) |
3881 // ----- Read the compressed file in a buffer (one shot) |
4264 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
3882 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
4265 |
3883 |
4266 // ----- Decompress the file |
3884 // ----- Decompress the file |
4267 $v_file_content = @gzinflate($v_buffer); |
3885 $v_file_content = @gzinflate($v_buffer); |
4268 unset($v_buffer); |
3886 unset($v_buffer); |
4269 if ($v_file_content === FALSE) { |
3887 if ($v_file_content === FALSE) { |
4270 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to inflate compressed file"); |
3888 |
4271 |
|
4272 // ----- Change the file status |
3889 // ----- Change the file status |
4273 // TBC |
3890 // TBC |
4274 $p_entry['status'] = "error"; |
3891 $p_entry['status'] = "error"; |
4275 |
3892 |
4276 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
4277 return $v_result; |
3893 return $v_result; |
4278 } |
3894 } |
4279 |
3895 |
4280 // ----- Opening destination file |
3896 // ----- Opening destination file |
4281 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { |
3897 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { |
4282 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); |
3898 |
4283 |
|
4284 // ----- Change the file status |
3899 // ----- Change the file status |
4285 $p_entry['status'] = "write_error"; |
3900 $p_entry['status'] = "write_error"; |
4286 |
3901 |
4287 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
4288 return $v_result; |
3902 return $v_result; |
4289 } |
3903 } |
4290 |
3904 |
4291 // ----- Write the uncompressed data |
3905 // ----- Write the uncompressed data |
4292 @fwrite($v_dest_file, $v_file_content, $p_entry['size']); |
3906 @fwrite($v_dest_file, $v_file_content, $p_entry['size']); |
4293 unset($v_file_content); |
3907 unset($v_file_content); |
4294 |
3908 |
4295 // ----- Closing the destination file |
3909 // ----- Closing the destination file |
4296 @fclose($v_dest_file); |
3910 @fclose($v_dest_file); |
4297 |
3911 |
4298 } |
3912 } |
4299 |
3913 |
4300 // ----- Change the file mtime |
3914 // ----- Change the file mtime |
4301 @touch($p_entry['filename'], $p_entry['mtime']); |
3915 @touch($p_entry['filename'], $p_entry['mtime']); |
4302 } |
3916 } |
4303 |
3917 |
4304 // ----- Look for chmod option |
3918 // ----- Look for chmod option |
4305 if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { |
3919 if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { |
4306 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "chmod option activated '".$p_options[PCLZIP_OPT_SET_CHMOD]."'"); |
|
4307 |
3920 |
4308 // ----- Change the mode of the file |
3921 // ----- Change the mode of the file |
4309 @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); |
3922 @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); |
4310 } |
3923 } |
4311 |
3924 |
4312 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); |
3925 } |
4313 } |
3926 } |
4314 } |
3927 |
4315 |
3928 // ----- Change abort status |
4316 // ----- Change abort status |
3929 if ($p_entry['status'] == "aborted") { |
4317 if ($p_entry['status'] == "aborted") { |
3930 $p_entry['status'] = "skipped"; |
4318 $p_entry['status'] = "skipped"; |
3931 } |
4319 } |
3932 |
4320 |
|
4321 // ----- Look for post-extract callback |
3933 // ----- Look for post-extract callback |
4322 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
3934 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
4323 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction"); |
|
4324 |
3935 |
4325 // ----- Generate a local information |
3936 // ----- Generate a local information |
4326 $v_local_header = array(); |
3937 $v_local_header = array(); |
4327 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
3938 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
4328 |
3939 |
4329 // ----- Call the callback |
3940 // ----- Call the callback |
4330 // Here I do not use call_user_func() because I need to send a reference to the |
3941 // Here I do not use call_user_func() because I need to send a reference to the |
4331 // header. |
3942 // header. |
4332 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); |
3943 $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
4333 |
3944 |
4334 // ----- Look for abort result |
3945 // ----- Look for abort result |
4335 if ($v_result == 2) { |
3946 if ($v_result == 2) { |
4336 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); |
|
4337 $v_result = PCLZIP_ERR_USER_ABORTED; |
3947 $v_result = PCLZIP_ERR_USER_ABORTED; |
4338 } |
3948 } |
4339 } |
3949 } |
4340 |
3950 |
4341 // ----- Return |
3951 // ----- Return |
4342 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
4343 return $v_result; |
3952 return $v_result; |
4344 } |
3953 } |
4345 // -------------------------------------------------------------------------------- |
3954 // -------------------------------------------------------------------------------- |
4346 |
3955 |
4347 // -------------------------------------------------------------------------------- |
3956 // -------------------------------------------------------------------------------- |
4350 // Parameters : |
3959 // Parameters : |
4351 // Return Values : |
3960 // Return Values : |
4352 // -------------------------------------------------------------------------------- |
3961 // -------------------------------------------------------------------------------- |
4353 function privExtractFileUsingTempFile(&$p_entry, &$p_options) |
3962 function privExtractFileUsingTempFile(&$p_entry, &$p_options) |
4354 { |
3963 { |
4355 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileUsingTempFile', "filename='".$p_entry['filename']."'"); |
|
4356 $v_result=1; |
3964 $v_result=1; |
4357 |
3965 |
4358 // ----- Creates a temporary file |
3966 // ----- Creates a temporary file |
4359 $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
3967 $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
4360 if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) { |
3968 if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) { |
4361 fclose($v_file); |
3969 fclose($v_file); |
4362 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
3970 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
4363 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
4364 return PclZip::errorCode(); |
3971 return PclZip::errorCode(); |
4365 } |
3972 } |
4366 |
3973 |
4367 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Start extraction of '".$p_entry['filename']."'"); |
|
4368 |
3974 |
4369 // ----- Write gz file format header |
3975 // ----- Write gz file format header |
4370 $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3)); |
3976 $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3)); |
4371 @fwrite($v_dest_file, $v_binary_data, 10); |
3977 @fwrite($v_dest_file, $v_binary_data, 10); |
4372 |
3978 |
4373 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
3979 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
4374 $v_size = $p_entry['compressed_size']; |
3980 $v_size = $p_entry['compressed_size']; |
4375 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Compressed Size :".$v_size.""); |
|
4376 while ($v_size != 0) |
3981 while ($v_size != 0) |
4377 { |
3982 { |
4378 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
3983 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
4379 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read ".$v_read_size." bytes"); |
|
4380 $v_buffer = @fread($this->zip_fd, $v_read_size); |
3984 $v_buffer = @fread($this->zip_fd, $v_read_size); |
4381 //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
3985 //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
4382 @fwrite($v_dest_file, $v_buffer, $v_read_size); |
3986 @fwrite($v_dest_file, $v_buffer, $v_read_size); |
4383 $v_size -= $v_read_size; |
3987 $v_size -= $v_read_size; |
4384 } |
3988 } |
4390 // ----- Close the temporary file |
3994 // ----- Close the temporary file |
4391 @fclose($v_dest_file); |
3995 @fclose($v_dest_file); |
4392 |
3996 |
4393 // ----- Opening destination file |
3997 // ----- Opening destination file |
4394 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { |
3998 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { |
4395 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); |
|
4396 $p_entry['status'] = "write_error"; |
3999 $p_entry['status'] = "write_error"; |
4397 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
4398 return $v_result; |
4000 return $v_result; |
4399 } |
4001 } |
4400 |
4002 |
4401 // ----- Open the temporary gz file |
4003 // ----- Open the temporary gz file |
4402 if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) { |
4004 if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) { |
4403 @fclose($v_dest_file); |
4005 @fclose($v_dest_file); |
4404 $p_entry['status'] = "read_error"; |
4006 $p_entry['status'] = "read_error"; |
4405 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
4007 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
4406 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
4407 return PclZip::errorCode(); |
4008 return PclZip::errorCode(); |
4408 } |
4009 } |
4409 |
4010 |
4410 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'File size is '.filesize($v_gzip_temp_name)); |
|
4411 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes"); |
|
4412 |
4011 |
4413 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
4012 // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
4414 $v_size = $p_entry['size']; |
4013 $v_size = $p_entry['size']; |
4415 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size :".$v_size.""); |
|
4416 while ($v_size != 0) { |
4014 while ($v_size != 0) { |
4417 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
4015 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
4418 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read ".$v_read_size." bytes"); |
|
4419 $v_buffer = @gzread($v_src_file, $v_read_size); |
4016 $v_buffer = @gzread($v_src_file, $v_read_size); |
4420 //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
4017 //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
4421 @fwrite($v_dest_file, $v_buffer, $v_read_size); |
4018 @fwrite($v_dest_file, $v_buffer, $v_read_size); |
4422 $v_size -= $v_read_size; |
4019 $v_size -= $v_read_size; |
4423 } |
4020 } |
4424 @fclose($v_dest_file); |
4021 @fclose($v_dest_file); |
4425 @gzclose($v_src_file); |
4022 @gzclose($v_src_file); |
4426 |
4023 |
4427 // ----- Delete the temporary file |
4024 // ----- Delete the temporary file |
4428 @unlink($v_gzip_temp_name); |
4025 @unlink($v_gzip_temp_name); |
4429 |
4026 |
4430 // ----- Return |
4027 // ----- Return |
4431 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
4432 return $v_result; |
4028 return $v_result; |
4433 } |
4029 } |
4434 // -------------------------------------------------------------------------------- |
4030 // -------------------------------------------------------------------------------- |
4435 |
4031 |
4436 // -------------------------------------------------------------------------------- |
4032 // -------------------------------------------------------------------------------- |
4439 // Parameters : |
4035 // Parameters : |
4440 // Return Values : |
4036 // Return Values : |
4441 // -------------------------------------------------------------------------------- |
4037 // -------------------------------------------------------------------------------- |
4442 function privExtractFileInOutput(&$p_entry, &$p_options) |
4038 function privExtractFileInOutput(&$p_entry, &$p_options) |
4443 { |
4039 { |
4444 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileInOutput', ""); |
|
4445 $v_result=1; |
4040 $v_result=1; |
4446 |
4041 |
4447 // ----- Read the file header |
4042 // ----- Read the file header |
4448 if (($v_result = $this->privReadFileHeader($v_header)) != 1) { |
4043 if (($v_result = $this->privReadFileHeader($v_header)) != 1) { |
4449 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
4450 return $v_result; |
4044 return $v_result; |
4451 } |
4045 } |
4452 |
4046 |
4453 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); |
|
4454 |
4047 |
4455 // ----- Check that the file header is coherent with $p_entry info |
4048 // ----- Check that the file header is coherent with $p_entry info |
4456 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
4049 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
4457 // TBC |
4050 // TBC |
4458 } |
4051 } |
4459 |
4052 |
4460 // ----- Look for pre-extract callback |
4053 // ----- Look for pre-extract callback |
4461 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
4054 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
4462 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction"); |
|
4463 |
4055 |
4464 // ----- Generate a local information |
4056 // ----- Generate a local information |
4465 $v_local_header = array(); |
4057 $v_local_header = array(); |
4466 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
4058 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
4467 |
4059 |
4468 // ----- Call the callback |
4060 // ----- Call the callback |
4469 // Here I do not use call_user_func() because I need to send a reference to the |
4061 // Here I do not use call_user_func() because I need to send a reference to the |
4470 // header. |
4062 // header. |
4471 eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); |
4063 // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); |
|
4064 $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
4472 if ($v_result == 0) { |
4065 if ($v_result == 0) { |
4473 // ----- Change the file status |
4066 // ----- Change the file status |
4474 $p_entry['status'] = "skipped"; |
4067 $p_entry['status'] = "skipped"; |
4475 $v_result = 1; |
4068 $v_result = 1; |
4476 } |
4069 } |
4477 |
4070 |
4478 // ----- Look for abort result |
4071 // ----- Look for abort result |
4479 if ($v_result == 2) { |
4072 if ($v_result == 2) { |
4480 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); |
|
4481 // ----- This status is internal and will be changed in 'skipped' |
4073 // ----- This status is internal and will be changed in 'skipped' |
4482 $p_entry['status'] = "aborted"; |
4074 $p_entry['status'] = "aborted"; |
4483 $v_result = PCLZIP_ERR_USER_ABORTED; |
4075 $v_result = PCLZIP_ERR_USER_ABORTED; |
4484 } |
4076 } |
4485 |
4077 |
4486 // ----- Update the informations |
4078 // ----- Update the informations |
4487 // Only some fields can be modified |
4079 // Only some fields can be modified |
4488 $p_entry['filename'] = $v_local_header['filename']; |
4080 $p_entry['filename'] = $v_local_header['filename']; |
4489 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'"); |
|
4490 } |
4081 } |
4491 |
4082 |
4492 // ----- Trace |
4083 // ----- Trace |
4493 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'"); |
|
4494 |
4084 |
4495 // ----- Look if extraction should be done |
4085 // ----- Look if extraction should be done |
4496 if ($p_entry['status'] == 'ok') { |
4086 if ($p_entry['status'] == 'ok') { |
4497 |
4087 |
4498 // ----- Do the extraction (if not a folder) |
4088 // ----- Do the extraction (if not a folder) |
4499 if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
4089 if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
4500 // ----- Look for not compressed file |
4090 // ----- Look for not compressed file |
4501 if ($p_entry['compressed_size'] == $p_entry['size']) { |
4091 if ($p_entry['compressed_size'] == $p_entry['size']) { |
4502 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); |
|
4503 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes"); |
|
4504 |
4092 |
4505 // ----- Read the file in a buffer (one shot) |
4093 // ----- Read the file in a buffer (one shot) |
4506 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
4094 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
4507 |
4095 |
4508 // ----- Send the file to the output |
4096 // ----- Send the file to the output |
4509 echo $v_buffer; |
4097 echo $v_buffer; |
4510 unset($v_buffer); |
4098 unset($v_buffer); |
4511 } |
4099 } |
4512 else { |
4100 else { |
4513 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file"); |
|
4514 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Reading '".$p_entry['size']."' bytes"); |
|
4515 |
4101 |
4516 // ----- Read the compressed file in a buffer (one shot) |
4102 // ----- Read the compressed file in a buffer (one shot) |
4517 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
4103 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
4518 |
4104 |
4519 // ----- Decompress the file |
4105 // ----- Decompress the file |
4520 $v_file_content = gzinflate($v_buffer); |
4106 $v_file_content = gzinflate($v_buffer); |
4521 unset($v_buffer); |
4107 unset($v_buffer); |
4522 |
4108 |
4523 // ----- Send the file to the output |
4109 // ----- Send the file to the output |
4524 echo $v_file_content; |
4110 echo $v_file_content; |
4525 unset($v_file_content); |
4111 unset($v_file_content); |
4526 } |
4112 } |
4527 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); |
|
4528 } |
4113 } |
4529 } |
4114 } |
4530 |
4115 |
4531 // ----- Change abort status |
4116 // ----- Change abort status |
4532 if ($p_entry['status'] == "aborted") { |
4117 if ($p_entry['status'] == "aborted") { |
4533 $p_entry['status'] = "skipped"; |
4118 $p_entry['status'] = "skipped"; |
4534 } |
4119 } |
4535 |
4120 |
4536 // ----- Look for post-extract callback |
4121 // ----- Look for post-extract callback |
4537 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
4122 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
4538 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction"); |
|
4539 |
4123 |
4540 // ----- Generate a local information |
4124 // ----- Generate a local information |
4541 $v_local_header = array(); |
4125 $v_local_header = array(); |
4542 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
4126 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
4543 |
4127 |
4544 // ----- Call the callback |
4128 // ----- Call the callback |
4545 // Here I do not use call_user_func() because I need to send a reference to the |
4129 // Here I do not use call_user_func() because I need to send a reference to the |
4546 // header. |
4130 // header. |
4547 eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); |
4131 $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
4548 |
4132 |
4549 // ----- Look for abort result |
4133 // ----- Look for abort result |
4550 if ($v_result == 2) { |
4134 if ($v_result == 2) { |
4551 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); |
|
4552 $v_result = PCLZIP_ERR_USER_ABORTED; |
4135 $v_result = PCLZIP_ERR_USER_ABORTED; |
4553 } |
4136 } |
4554 } |
4137 } |
4555 |
4138 |
4556 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
4557 return $v_result; |
4139 return $v_result; |
4558 } |
4140 } |
4559 // -------------------------------------------------------------------------------- |
4141 // -------------------------------------------------------------------------------- |
4560 |
4142 |
4561 // -------------------------------------------------------------------------------- |
4143 // -------------------------------------------------------------------------------- |
4562 // Function : privExtractFileAsString() |
4144 // Function : privExtractFileAsString() |
4563 // Description : |
4145 // Description : |
4564 // Parameters : |
4146 // Parameters : |
4565 // Return Values : |
4147 // Return Values : |
4566 // -------------------------------------------------------------------------------- |
4148 // -------------------------------------------------------------------------------- |
4567 function privExtractFileAsString(&$p_entry, &$p_string) |
4149 function privExtractFileAsString(&$p_entry, &$p_string, &$p_options) |
4568 { |
4150 { |
4569 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileAsString', "p_entry['filename']='".$p_entry['filename']."'"); |
|
4570 $v_result=1; |
4151 $v_result=1; |
4571 |
4152 |
4572 // ----- Read the file header |
4153 // ----- Read the file header |
4573 $v_header = array(); |
4154 $v_header = array(); |
4574 if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
4155 if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
4575 { |
4156 { |
4576 // ----- Return |
4157 // ----- Return |
4577 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
4578 return $v_result; |
4158 return $v_result; |
4579 } |
4159 } |
4580 |
4160 |
4581 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); |
|
4582 |
4161 |
4583 // ----- Check that the file header is coherent with $p_entry info |
4162 // ----- Check that the file header is coherent with $p_entry info |
4584 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
4163 if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
4585 // TBC |
4164 // TBC |
4586 } |
4165 } |
4587 |
4166 |
4588 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file in string (with path) '".$p_entry['filename']."', size '$v_header[size]'"); |
4167 // ----- Look for pre-extract callback |
4589 |
4168 if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
4590 // ----- Do the extraction (if not a folder) |
4169 |
4591 if (!(($p_entry['external']&0x00000010)==0x00000010)) |
4170 // ----- Generate a local information |
4592 { |
4171 $v_local_header = array(); |
4593 // ----- Look for not compressed file |
4172 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
4594 // if ($p_entry['compressed_size'] == $p_entry['size']) |
4173 |
4595 if ($p_entry['compression'] == 0) { |
4174 // ----- Call the callback |
4596 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); |
4175 // Here I do not use call_user_func() because I need to send a reference to the |
4597 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes"); |
4176 // header. |
4598 |
4177 $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
4599 // ----- Reading the file |
4178 if ($v_result == 0) { |
4600 $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); |
4179 // ----- Change the file status |
|
4180 $p_entry['status'] = "skipped"; |
|
4181 $v_result = 1; |
|
4182 } |
|
4183 |
|
4184 // ----- Look for abort result |
|
4185 if ($v_result == 2) { |
|
4186 // ----- This status is internal and will be changed in 'skipped' |
|
4187 $p_entry['status'] = "aborted"; |
|
4188 $v_result = PCLZIP_ERR_USER_ABORTED; |
|
4189 } |
|
4190 |
|
4191 // ----- Update the informations |
|
4192 // Only some fields can be modified |
|
4193 $p_entry['filename'] = $v_local_header['filename']; |
|
4194 } |
|
4195 |
|
4196 |
|
4197 // ----- Look if extraction should be done |
|
4198 if ($p_entry['status'] == 'ok') { |
|
4199 |
|
4200 // ----- Do the extraction (if not a folder) |
|
4201 if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
4202 // ----- Look for not compressed file |
|
4203 // if ($p_entry['compressed_size'] == $p_entry['size']) |
|
4204 if ($p_entry['compression'] == 0) { |
|
4205 |
|
4206 // ----- Reading the file |
|
4207 $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
4208 } |
|
4209 else { |
|
4210 |
|
4211 // ----- Reading the file |
|
4212 $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
4213 |
|
4214 // ----- Decompress the file |
|
4215 if (($p_string = @gzinflate($v_data)) === FALSE) { |
|
4216 // TBC |
|
4217 } |
|
4218 } |
|
4219 |
|
4220 // ----- Trace |
4601 } |
4221 } |
4602 else { |
4222 else { |
4603 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (compression method '".$p_entry['compression']."')"); |
4223 // TBC : error : can not extract a folder in a string |
4604 |
4224 } |
4605 // ----- Reading the file |
4225 |
4606 $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); |
4226 } |
4607 |
4227 |
4608 // ----- Decompress the file |
4228 // ----- Change abort status |
4609 if (($p_string = @gzinflate($v_data)) === FALSE) { |
4229 if ($p_entry['status'] == "aborted") { |
4610 // TBC |
4230 $p_entry['status'] = "skipped"; |
4611 } |
4231 } |
4612 } |
4232 |
4613 |
4233 // ----- Look for post-extract callback |
4614 // ----- Trace |
4234 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
4615 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); |
4235 |
4616 } |
4236 // ----- Generate a local information |
4617 else { |
4237 $v_local_header = array(); |
4618 // TBC : error : can not extract a folder in a string |
4238 $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
4239 |
|
4240 // ----- Swap the content to header |
|
4241 $v_local_header['content'] = $p_string; |
|
4242 $p_string = ''; |
|
4243 |
|
4244 // ----- Call the callback |
|
4245 // Here I do not use call_user_func() because I need to send a reference to the |
|
4246 // header. |
|
4247 $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
4248 |
|
4249 // ----- Swap back the content to header |
|
4250 $p_string = $v_local_header['content']; |
|
4251 unset($v_local_header['content']); |
|
4252 |
|
4253 // ----- Look for abort result |
|
4254 if ($v_result == 2) { |
|
4255 $v_result = PCLZIP_ERR_USER_ABORTED; |
|
4256 } |
4619 } |
4257 } |
4620 |
4258 |
4621 // ----- Return |
4259 // ----- Return |
4622 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
4623 return $v_result; |
4260 return $v_result; |
4624 } |
4261 } |
4625 // -------------------------------------------------------------------------------- |
4262 // -------------------------------------------------------------------------------- |
4626 |
4263 |
4627 // -------------------------------------------------------------------------------- |
4264 // -------------------------------------------------------------------------------- |
4660 // ----- Look for invalid block size |
4292 // ----- Look for invalid block size |
4661 if (strlen($v_binary_data) != 26) |
4293 if (strlen($v_binary_data) != 26) |
4662 { |
4294 { |
4663 $p_header['filename'] = ""; |
4295 $p_header['filename'] = ""; |
4664 $p_header['status'] = "invalid_header"; |
4296 $p_header['status'] = "invalid_header"; |
4665 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data)); |
|
4666 |
4297 |
4667 // ----- Error log |
4298 // ----- Error log |
4668 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
4299 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
4669 |
4300 |
4670 // ----- Return |
4301 // ----- Return |
4671 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
4672 return PclZip::errorCode(); |
4302 return PclZip::errorCode(); |
4673 } |
4303 } |
4674 |
4304 |
4675 // ----- Extract the values |
4305 // ----- Extract the values |
4676 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header : '".$v_binary_data."'"); |
|
4677 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header (Hex) : '".bin2hex($v_binary_data)."'"); |
|
4678 $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); |
4306 $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); |
4679 |
4307 |
4680 // ----- Get filename |
4308 // ----- Get filename |
4681 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "File name length : ".$v_data['filename_len']); |
|
4682 $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); |
4309 $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); |
4683 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename : \''.$p_header['filename'].'\''); |
|
4684 |
4310 |
4685 // ----- Get extra_fields |
4311 // ----- Get extra_fields |
4686 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extra field length : ".$v_data['extra_len']); |
|
4687 if ($v_data['extra_len'] != 0) { |
4312 if ($v_data['extra_len'] != 0) { |
4688 $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); |
4313 $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); |
4689 } |
4314 } |
4690 else { |
4315 else { |
4691 $p_header['extra'] = ''; |
4316 $p_header['extra'] = ''; |
4692 } |
4317 } |
4693 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Extra field : \''.bin2hex($p_header['extra']).'\''); |
|
4694 |
4318 |
4695 // ----- Extract properties |
4319 // ----- Extract properties |
4696 $p_header['version_extracted'] = $v_data['version']; |
4320 $p_header['version_extracted'] = $v_data['version']; |
4697 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : ('.$p_header['version_extracted'].') \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\''); |
|
4698 $p_header['compression'] = $v_data['compression']; |
4321 $p_header['compression'] = $v_data['compression']; |
4699 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compression method : \''.$p_header['compression'].'\''); |
|
4700 $p_header['size'] = $v_data['size']; |
4322 $p_header['size'] = $v_data['size']; |
4701 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_header['size'].'\''); |
|
4702 $p_header['compressed_size'] = $v_data['compressed_size']; |
4323 $p_header['compressed_size'] = $v_data['compressed_size']; |
4703 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_header['compressed_size'].'\''); |
|
4704 $p_header['crc'] = $v_data['crc']; |
4324 $p_header['crc'] = $v_data['crc']; |
4705 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); |
|
4706 $p_header['flag'] = $v_data['flag']; |
4325 $p_header['flag'] = $v_data['flag']; |
4707 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag : \''.$p_header['flag'].'\''); |
|
4708 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag bit 11 (from right) : \''.($p_header['flag']&0x0400).'\''); |
|
4709 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag bit 11 (from left) : \''.($p_header['flag']&0x0020).'\''); |
|
4710 $p_header['filename_len'] = $v_data['filename_len']; |
4326 $p_header['filename_len'] = $v_data['filename_len']; |
4711 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename_len : \''.$p_header['filename_len'].'\''); |
|
4712 |
4327 |
4713 // ----- Recuperate date in UNIX format |
4328 // ----- Recuperate date in UNIX format |
4714 $p_header['mdate'] = $v_data['mdate']; |
4329 $p_header['mdate'] = $v_data['mdate']; |
4715 $p_header['mtime'] = $v_data['mtime']; |
4330 $p_header['mtime'] = $v_data['mtime']; |
4716 if ($p_header['mdate'] && $p_header['mtime']) |
4331 if ($p_header['mdate'] && $p_header['mtime']) |
4789 // ----- Look for invalid block size |
4395 // ----- Look for invalid block size |
4790 if (strlen($v_binary_data) != 42) |
4396 if (strlen($v_binary_data) != 42) |
4791 { |
4397 { |
4792 $p_header['filename'] = ""; |
4398 $p_header['filename'] = ""; |
4793 $p_header['status'] = "invalid_header"; |
4399 $p_header['status'] = "invalid_header"; |
4794 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data)); |
|
4795 |
4400 |
4796 // ----- Error log |
4401 // ----- Error log |
4797 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
4402 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
4798 |
4403 |
4799 // ----- Return |
4404 // ----- Return |
4800 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
4801 return PclZip::errorCode(); |
4405 return PclZip::errorCode(); |
4802 } |
4406 } |
4803 |
4407 |
4804 // ----- Extract the values |
4408 // ----- Extract the values |
4805 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header : '".$v_binary_data."'"); |
|
4806 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header (Hex) : '".bin2hex($v_binary_data)."'"); |
|
4807 $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data); |
4409 $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data); |
4808 |
4410 |
4809 // ----- Get filename |
4411 // ----- Get filename |
4810 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File name length : ".$p_header['filename_len']); |
|
4811 if ($p_header['filename_len'] != 0) |
4412 if ($p_header['filename_len'] != 0) |
4812 $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); |
4413 $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); |
4813 else |
4414 else |
4814 $p_header['filename'] = ''; |
4415 $p_header['filename'] = ''; |
4815 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Filename : \''.$p_header['filename'].'\''); |
|
4816 |
4416 |
4817 // ----- Get extra |
4417 // ----- Get extra |
4818 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Extra length : ".$p_header['extra_len']); |
|
4819 if ($p_header['extra_len'] != 0) |
4418 if ($p_header['extra_len'] != 0) |
4820 $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); |
4419 $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); |
4821 else |
4420 else |
4822 $p_header['extra'] = ''; |
4421 $p_header['extra'] = ''; |
4823 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Extra : \''.$p_header['extra'].'\''); |
|
4824 |
4422 |
4825 // ----- Get comment |
4423 // ----- Get comment |
4826 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Comment length : ".$p_header['comment_len']); |
|
4827 if ($p_header['comment_len'] != 0) |
4424 if ($p_header['comment_len'] != 0) |
4828 $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); |
4425 $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); |
4829 else |
4426 else |
4830 $p_header['comment'] = ''; |
4427 $p_header['comment'] = ''; |
4831 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Comment : \''.$p_header['comment'].'\''); |
|
4832 |
4428 |
4833 // ----- Extract properties |
4429 // ----- Extract properties |
4834 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version : \''.($p_header['version']/10).'.'.($p_header['version']%10).'\''); |
|
4835 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\''); |
|
4836 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Size : \''.$p_header['size'].'\''); |
|
4837 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Compressed Size : \''.$p_header['compressed_size'].'\''); |
|
4838 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); |
|
4839 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Flag : \''.$p_header['flag'].'\''); |
|
4840 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Offset : \''.$p_header['offset'].'\''); |
|
4841 |
4430 |
4842 // ----- Recuperate date in UNIX format |
4431 // ----- Recuperate date in UNIX format |
4843 //if ($p_header['mdate'] && $p_header['mtime']) |
4432 //if ($p_header['mdate'] && $p_header['mtime']) |
4844 // TBC : bug : this was ignoring time with 0/0/0 |
4433 // TBC : bug : this was ignoring time with 0/0/0 |
4845 if (1) |
4434 if (1) |
4896 // 1 on success, |
4478 // 1 on success, |
4897 // 0 on error; |
4479 // 0 on error; |
4898 // -------------------------------------------------------------------------------- |
4480 // -------------------------------------------------------------------------------- |
4899 function privCheckFileHeaders(&$p_local_header, &$p_central_header) |
4481 function privCheckFileHeaders(&$p_local_header, &$p_central_header) |
4900 { |
4482 { |
4901 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFileHeaders", ""); |
|
4902 $v_result=1; |
4483 $v_result=1; |
4903 |
4484 |
4904 // ----- Check the static values |
4485 // ----- Check the static values |
4905 // TBC |
4486 // TBC |
4906 if ($p_local_header['filename'] != $p_central_header['filename']) { |
4487 if ($p_local_header['filename'] != $p_central_header['filename']) { |
4907 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename" : TBC To Be Completed'); |
|
4908 } |
4488 } |
4909 if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { |
4489 if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { |
4910 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "version_extracted" : TBC To Be Completed'); |
|
4911 } |
4490 } |
4912 if ($p_local_header['flag'] != $p_central_header['flag']) { |
4491 if ($p_local_header['flag'] != $p_central_header['flag']) { |
4913 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "flag" : TBC To Be Completed'); |
|
4914 } |
4492 } |
4915 if ($p_local_header['compression'] != $p_central_header['compression']) { |
4493 if ($p_local_header['compression'] != $p_central_header['compression']) { |
4916 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "compression" : TBC To Be Completed'); |
|
4917 } |
4494 } |
4918 if ($p_local_header['mtime'] != $p_central_header['mtime']) { |
4495 if ($p_local_header['mtime'] != $p_central_header['mtime']) { |
4919 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "mtime" : TBC To Be Completed'); |
|
4920 } |
4496 } |
4921 if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { |
4497 if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { |
4922 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename_len" : TBC To Be Completed'); |
|
4923 } |
4498 } |
4924 |
4499 |
4925 // ----- Look for flag bit 3 |
4500 // ----- Look for flag bit 3 |
4926 if (($p_local_header['flag'] & 8) == 8) { |
4501 if (($p_local_header['flag'] & 8) == 8) { |
4927 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Purpose bit flag bit 3 set !'); |
|
4928 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'File size, compression size and crc found in central header'); |
|
4929 $p_local_header['size'] = $p_central_header['size']; |
4502 $p_local_header['size'] = $p_central_header['size']; |
4930 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_local_header['size'].'\''); |
|
4931 $p_local_header['compressed_size'] = $p_central_header['compressed_size']; |
4503 $p_local_header['compressed_size'] = $p_central_header['compressed_size']; |
4932 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_local_header['compressed_size'].'\''); |
|
4933 $p_local_header['crc'] = $p_central_header['crc']; |
4504 $p_local_header['crc'] = $p_central_header['crc']; |
4934 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_local_header['crc']).'\''); |
|
4935 } |
4505 } |
4936 |
4506 |
4937 // ----- Return |
4507 // ----- Return |
4938 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
4939 return $v_result; |
4508 return $v_result; |
4940 } |
4509 } |
4941 // -------------------------------------------------------------------------------- |
4510 // -------------------------------------------------------------------------------- |
4942 |
4511 |
4943 // -------------------------------------------------------------------------------- |
4512 // -------------------------------------------------------------------------------- |
4946 // Parameters : |
4515 // Parameters : |
4947 // Return Values : |
4516 // Return Values : |
4948 // -------------------------------------------------------------------------------- |
4517 // -------------------------------------------------------------------------------- |
4949 function privReadEndCentralDir(&$p_central_dir) |
4518 function privReadEndCentralDir(&$p_central_dir) |
4950 { |
4519 { |
4951 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadEndCentralDir", ""); |
|
4952 $v_result=1; |
4520 $v_result=1; |
4953 |
4521 |
4954 // ----- Go to the end of the zip file |
4522 // ----- Go to the end of the zip file |
4955 $v_size = filesize($this->zipname); |
4523 $v_size = filesize($this->zipname); |
4956 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size of the file :$v_size"); |
|
4957 @fseek($this->zip_fd, $v_size); |
4524 @fseek($this->zip_fd, $v_size); |
4958 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position at end of zip file : \''.ftell($this->zip_fd).'\''); |
|
4959 if (@ftell($this->zip_fd) != $v_size) |
4525 if (@ftell($this->zip_fd) != $v_size) |
4960 { |
4526 { |
4961 // ----- Error log |
4527 // ----- Error log |
4962 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); |
4528 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); |
4963 |
4529 |
4964 // ----- Return |
4530 // ----- Return |
4965 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
4966 return PclZip::errorCode(); |
4531 return PclZip::errorCode(); |
4967 } |
4532 } |
4968 |
4533 |
4969 // ----- First try : look if this is an archive with no commentaries (most of the time) |
4534 // ----- First try : look if this is an archive with no commentaries (most of the time) |
4970 // in this case the end of central dir is at 22 bytes of the file end |
4535 // in this case the end of central dir is at 22 bytes of the file end |
4971 $v_found = 0; |
4536 $v_found = 0; |
4972 if ($v_size > 26) { |
4537 if ($v_size > 26) { |
4973 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Look for central dir with no comment'); |
|
4974 @fseek($this->zip_fd, $v_size-22); |
4538 @fseek($this->zip_fd, $v_size-22); |
4975 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after min central position : \''.ftell($this->zip_fd).'\''); |
|
4976 if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) |
4539 if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) |
4977 { |
4540 { |
4978 // ----- Error log |
4541 // ----- Error log |
4979 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
4542 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
4980 |
4543 |
4981 // ----- Return |
4544 // ----- Return |
4982 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
4983 return PclZip::errorCode(); |
4545 return PclZip::errorCode(); |
4984 } |
4546 } |
4985 |
4547 |
4986 // ----- Read for bytes |
4548 // ----- Read for bytes |
4987 $v_binary_data = @fread($this->zip_fd, 4); |
4549 $v_binary_data = @fread($this->zip_fd, 4); |
4988 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); |
|
4989 $v_data = @unpack('Vid', $v_binary_data); |
4550 $v_data = @unpack('Vid', $v_binary_data); |
4990 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); |
|
4991 |
4551 |
4992 // ----- Check signature |
4552 // ----- Check signature |
4993 if ($v_data['id'] == 0x06054b50) { |
4553 if ($v_data['id'] == 0x06054b50) { |
4994 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found central dir at the default position."); |
|
4995 $v_found = 1; |
4554 $v_found = 1; |
4996 } |
4555 } |
4997 |
4556 |
4998 $v_pos = ftell($this->zip_fd); |
4557 $v_pos = ftell($this->zip_fd); |
4999 } |
4558 } |
5000 |
4559 |
5001 // ----- Go back to the maximum possible size of the Central Dir End Record |
4560 // ----- Go back to the maximum possible size of the Central Dir End Record |
5002 if (!$v_found) { |
4561 if (!$v_found) { |
5003 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Start extended search of end central dir'); |
|
5004 $v_maximum_size = 65557; // 0xFFFF + 22; |
4562 $v_maximum_size = 65557; // 0xFFFF + 22; |
5005 if ($v_maximum_size > $v_size) |
4563 if ($v_maximum_size > $v_size) |
5006 $v_maximum_size = $v_size; |
4564 $v_maximum_size = $v_size; |
5007 @fseek($this->zip_fd, $v_size-$v_maximum_size); |
4565 @fseek($this->zip_fd, $v_size-$v_maximum_size); |
5008 if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) |
4566 if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) |
5009 { |
4567 { |
5010 // ----- Error log |
4568 // ----- Error log |
5011 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
4569 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
5012 |
4570 |
5013 // ----- Return |
4571 // ----- Return |
5014 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
5015 return PclZip::errorCode(); |
4572 return PclZip::errorCode(); |
5016 } |
4573 } |
5017 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after max central position : \''.ftell($this->zip_fd).'\''); |
|
5018 |
4574 |
5019 // ----- Read byte per byte in order to find the signature |
4575 // ----- Read byte per byte in order to find the signature |
5020 $v_pos = ftell($this->zip_fd); |
4576 $v_pos = ftell($this->zip_fd); |
5021 $v_bytes = 0x00000000; |
4577 $v_bytes = 0x00000000; |
5022 while ($v_pos < $v_size) |
4578 while ($v_pos < $v_size) |
5023 { |
4579 { |
5024 // ----- Read a byte |
4580 // ----- Read a byte |
5025 $v_byte = @fread($this->zip_fd, 1); |
4581 $v_byte = @fread($this->zip_fd, 1); |
5026 |
4582 |
5027 // ----- Add the byte |
4583 // ----- Add the byte |
5028 // $v_bytes = ($v_bytes << 8) | Ord($v_byte); |
4584 //$v_bytes = ($v_bytes << 8) | Ord($v_byte); |
5029 // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number |
4585 // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number |
5030 // Otherwise on systems where we have 64bit integers the check below for the magic number will fail. |
4586 // Otherwise on systems where we have 64bit integers the check below for the magic number will fail. |
5031 $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); |
4587 $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); |
5032 |
4588 |
5033 // ----- Compare the bytes |
4589 // ----- Compare the bytes |
5034 if ($v_bytes == 0x504b0506) |
4590 if ($v_bytes == 0x504b0506) |
5035 { |
4591 { |
5036 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Found End Central Dir signature at position : \''.ftell($this->zip_fd).'\''); |
|
5037 $v_pos++; |
4592 $v_pos++; |
5038 break; |
4593 break; |
5039 } |
4594 } |
5040 |
4595 |
5041 $v_pos++; |
4596 $v_pos++; |
5042 } |
4597 } |
5043 |
4598 |
5044 // ----- Look if not found end of central dir |
4599 // ----- Look if not found end of central dir |
5045 if ($v_pos == $v_size) |
4600 if ($v_pos == $v_size) |
5046 { |
4601 { |
5047 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to find End of Central Dir Record signature"); |
|
5048 |
4602 |
5049 // ----- Error log |
4603 // ----- Error log |
5050 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); |
4604 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); |
5051 |
4605 |
5052 // ----- Return |
4606 // ----- Return |
5053 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
5054 return PclZip::errorCode(); |
4607 return PclZip::errorCode(); |
5055 } |
4608 } |
5056 } |
4609 } |
5057 |
4610 |
5058 // ----- Read the first 18 bytes of the header |
4611 // ----- Read the first 18 bytes of the header |
5059 $v_binary_data = fread($this->zip_fd, 18); |
4612 $v_binary_data = fread($this->zip_fd, 18); |
5060 |
4613 |
5061 // ----- Look for invalid block size |
4614 // ----- Look for invalid block size |
5062 if (strlen($v_binary_data) != 18) |
4615 if (strlen($v_binary_data) != 18) |
5063 { |
4616 { |
5064 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); |
|
5065 |
4617 |
5066 // ----- Error log |
4618 // ----- Error log |
5067 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); |
4619 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); |
5068 |
4620 |
5069 // ----- Return |
4621 // ----- Return |
5070 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
5071 return PclZip::errorCode(); |
4622 return PclZip::errorCode(); |
5072 } |
4623 } |
5073 |
4624 |
5074 // ----- Extract the values |
4625 // ----- Extract the values |
5075 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record : '".$v_binary_data."'"); |
|
5076 ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record (Hex) : '".bin2hex($v_binary_data)."'"); |
|
5077 $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); |
4626 $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); |
5078 |
4627 |
5079 // ----- Check the global size |
4628 // ----- Check the global size |
5080 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Comment length : ".$v_data['comment_size']); |
|
5081 if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { |
4629 if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { |
5082 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The central dir is not at the end of the archive. Some trailing bytes exists after the archive."); |
|
5083 |
4630 |
5084 // ----- Removed in release 2.2 see readme file |
4631 // ----- Removed in release 2.2 see readme file |
5085 // The check of the file size is a little too strict. |
4632 // The check of the file size is a little too strict. |
5086 // Some bugs where found when a zip is encrypted/decrypted with 'crypt'. |
4633 // Some bugs where found when a zip is encrypted/decrypted with 'crypt'. |
5087 // While decrypted, zip has training 0 bytes |
4634 // While decrypted, zip has training 0 bytes |
5090 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, |
4637 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, |
5091 'The central dir is not at the end of the archive.' |
4638 'The central dir is not at the end of the archive.' |
5092 .' Some trailing bytes exists after the archive.'); |
4639 .' Some trailing bytes exists after the archive.'); |
5093 |
4640 |
5094 // ----- Return |
4641 // ----- Return |
5095 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
5096 return PclZip::errorCode(); |
4642 return PclZip::errorCode(); |
5097 } |
4643 } |
5098 } |
4644 } |
5099 |
4645 |
5100 // ----- Get comment |
4646 // ----- Get comment |
5101 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment size : \''.$v_data['comment_size'].'\''); |
|
5102 if ($v_data['comment_size'] != 0) { |
4647 if ($v_data['comment_size'] != 0) { |
5103 $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); |
4648 $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); |
5104 } |
4649 } |
5105 else |
4650 else |
5106 $p_central_dir['comment'] = ''; |
4651 $p_central_dir['comment'] = ''; |
5107 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment : \''.$p_central_dir['comment'].'\''); |
|
5108 |
4652 |
5109 $p_central_dir['entries'] = $v_data['entries']; |
4653 $p_central_dir['entries'] = $v_data['entries']; |
5110 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries : \''.$p_central_dir['entries'].'\''); |
|
5111 $p_central_dir['disk_entries'] = $v_data['disk_entries']; |
4654 $p_central_dir['disk_entries'] = $v_data['disk_entries']; |
5112 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries for this disk : \''.$p_central_dir['disk_entries'].'\''); |
|
5113 $p_central_dir['offset'] = $v_data['offset']; |
4655 $p_central_dir['offset'] = $v_data['offset']; |
5114 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Offset of Central Dir : \''.$p_central_dir['offset'].'\''); |
|
5115 $p_central_dir['size'] = $v_data['size']; |
4656 $p_central_dir['size'] = $v_data['size']; |
5116 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size of Central Dir : \''.$p_central_dir['size'].'\''); |
|
5117 $p_central_dir['disk'] = $v_data['disk']; |
4657 $p_central_dir['disk'] = $v_data['disk']; |
5118 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Disk number : \''.$p_central_dir['disk'].'\''); |
|
5119 $p_central_dir['disk_start'] = $v_data['disk_start']; |
4658 $p_central_dir['disk_start'] = $v_data['disk_start']; |
5120 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Start disk number : \''.$p_central_dir['disk_start'].'\''); |
|
5121 |
4659 |
5122 // TBC |
4660 // TBC |
5123 //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) { |
4661 //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) { |
5124 // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "central_dir[$key] = ".$p_central_dir[$key]); |
|
5125 //} |
4662 //} |
5126 |
4663 |
5127 // ----- Return |
4664 // ----- Return |
5128 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5129 return $v_result; |
4665 return $v_result; |
5130 } |
4666 } |
5131 // -------------------------------------------------------------------------------- |
4667 // -------------------------------------------------------------------------------- |
5132 |
4668 |
5133 // -------------------------------------------------------------------------------- |
4669 // -------------------------------------------------------------------------------- |
5136 // Parameters : |
4672 // Parameters : |
5137 // Return Values : |
4673 // Return Values : |
5138 // -------------------------------------------------------------------------------- |
4674 // -------------------------------------------------------------------------------- |
5139 function privDeleteByRule(&$p_result_list, &$p_options) |
4675 function privDeleteByRule(&$p_result_list, &$p_options) |
5140 { |
4676 { |
5141 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByRule", ""); |
|
5142 $v_result=1; |
4677 $v_result=1; |
5143 $v_list_detail = array(); |
4678 $v_list_detail = array(); |
5144 |
4679 |
5145 // ----- Open the zip file |
4680 // ----- Open the zip file |
5146 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); |
|
5147 if (($v_result=$this->privOpenFd('rb')) != 1) |
4681 if (($v_result=$this->privOpenFd('rb')) != 1) |
5148 { |
4682 { |
5149 // ----- Return |
4683 // ----- Return |
5150 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5151 return $v_result; |
4684 return $v_result; |
5152 } |
4685 } |
5153 |
4686 |
5154 // ----- Read the central directory informations |
4687 // ----- Read the central directory informations |
5155 $v_central_dir = array(); |
4688 $v_central_dir = array(); |
5156 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
4689 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
5157 { |
4690 { |
5158 $this->privCloseFd(); |
4691 $this->privCloseFd(); |
5159 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5160 return $v_result; |
4692 return $v_result; |
5161 } |
4693 } |
5162 |
4694 |
5163 // ----- Go to beginning of File |
4695 // ----- Go to beginning of File |
5164 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); |
|
5165 @rewind($this->zip_fd); |
4696 @rewind($this->zip_fd); |
5166 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); |
|
5167 |
4697 |
5168 // ----- Scan all the files |
4698 // ----- Scan all the files |
5169 // ----- Start at beginning of Central Dir |
4699 // ----- Start at beginning of Central Dir |
5170 $v_pos_entry = $v_central_dir['offset']; |
4700 $v_pos_entry = $v_central_dir['offset']; |
5171 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); |
|
5172 @rewind($this->zip_fd); |
4701 @rewind($this->zip_fd); |
5173 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); |
|
5174 if (@fseek($this->zip_fd, $v_pos_entry)) |
4702 if (@fseek($this->zip_fd, $v_pos_entry)) |
5175 { |
4703 { |
5176 // ----- Close the zip file |
4704 // ----- Close the zip file |
5177 $this->privCloseFd(); |
4705 $this->privCloseFd(); |
5178 |
4706 |
5179 // ----- Error log |
4707 // ----- Error log |
5180 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
4708 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
5181 |
4709 |
5182 // ----- Return |
4710 // ----- Return |
5183 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
5184 return PclZip::errorCode(); |
4711 return PclZip::errorCode(); |
5185 } |
4712 } |
5186 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); |
|
5187 |
4713 |
5188 // ----- Read each entry |
4714 // ----- Read each entry |
5189 $v_header_list = array(); |
4715 $v_header_list = array(); |
5190 $j_start = 0; |
4716 $j_start = 0; |
5191 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
4717 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
5192 { |
4718 { |
5193 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry (index '$i')"); |
|
5194 |
4719 |
5195 // ----- Read the file header |
4720 // ----- Read the file header |
5196 $v_header_list[$v_nb_extracted] = array(); |
4721 $v_header_list[$v_nb_extracted] = array(); |
5197 if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) |
4722 if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) |
5198 { |
4723 { |
5199 // ----- Close the zip file |
4724 // ----- Close the zip file |
5200 $this->privCloseFd(); |
4725 $this->privCloseFd(); |
5201 |
4726 |
5202 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5203 return $v_result; |
4727 return $v_result; |
5204 } |
4728 } |
5205 |
4729 |
5206 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename (index '$i') : '".$v_header_list[$v_nb_extracted]['stored_filename']."'"); |
|
5207 |
4730 |
5208 // ----- Store the index |
4731 // ----- Store the index |
5209 $v_header_list[$v_nb_extracted]['index'] = $i; |
4732 $v_header_list[$v_nb_extracted]['index'] = $i; |
5210 |
4733 |
5211 // ----- Look for the specific extract rules |
4734 // ----- Look for the specific extract rules |
5212 $v_found = false; |
4735 $v_found = false; |
5213 |
4736 |
5214 // ----- Look for extract by name rule |
4737 // ----- Look for extract by name rule |
5215 if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
4738 if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
5216 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
4739 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
5217 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'"); |
|
5218 |
4740 |
5219 // ----- Look if the filename is in the list |
4741 // ----- Look if the filename is in the list |
5220 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { |
4742 for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { |
5221 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'"); |
|
5222 |
4743 |
5223 // ----- Look for a directory |
4744 // ----- Look for a directory |
5224 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
4745 if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
5225 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory"); |
|
5226 |
4746 |
5227 // ----- Look if the directory is in the filename path |
4747 // ----- Look if the directory is in the filename path |
5228 if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
4748 if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
5229 && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
4749 && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
5230 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path"); |
|
5231 $v_found = true; |
4750 $v_found = true; |
5232 } |
4751 } |
5233 elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ |
4752 elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ |
5234 && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
4753 && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
5235 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The entry is the searched directory"); |
|
5236 $v_found = true; |
4754 $v_found = true; |
5237 } |
4755 } |
5238 } |
4756 } |
5239 // ----- Look for a filename |
4757 // ----- Look for a filename |
5240 elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
4758 elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
5241 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one."); |
|
5242 $v_found = true; |
4759 $v_found = true; |
5243 } |
4760 } |
5244 } |
4761 } |
5245 } |
4762 } |
5246 |
4763 |
5247 // ----- Look for extract by ereg rule |
4764 // ----- Look for extract by ereg rule |
|
4765 // ereg() is deprecated with PHP 5.3 |
|
4766 /* |
5248 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) |
4767 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) |
5249 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { |
4768 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { |
5250 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'"); |
|
5251 |
4769 |
5252 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { |
4770 if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { |
5253 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); |
|
5254 $v_found = true; |
4771 $v_found = true; |
5255 } |
4772 } |
5256 } |
4773 } |
|
4774 */ |
5257 |
4775 |
5258 // ----- Look for extract by preg rule |
4776 // ----- Look for extract by preg rule |
5259 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
4777 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
5260 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
4778 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
5261 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'"); |
|
5262 |
4779 |
5263 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { |
4780 if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { |
5264 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); |
|
5265 $v_found = true; |
4781 $v_found = true; |
5266 } |
4782 } |
5267 } |
4783 } |
5268 |
4784 |
5269 // ----- Look for extract by index rule |
4785 // ----- Look for extract by index rule |
5270 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
4786 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
5271 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
4787 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
5272 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'"); |
|
5273 |
4788 |
5274 // ----- Look if the index is in the list |
4789 // ----- Look if the index is in the list |
5275 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { |
4790 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { |
5276 //--(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']."]"); |
|
5277 |
4791 |
5278 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
4792 if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
5279 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range"); |
|
5280 $v_found = true; |
4793 $v_found = true; |
5281 } |
4794 } |
5282 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
4795 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
5283 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop"); |
|
5284 $j_start = $j+1; |
4796 $j_start = $j+1; |
5285 } |
4797 } |
5286 |
4798 |
5287 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
4799 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
5288 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop"); |
|
5289 break; |
4800 break; |
5290 } |
4801 } |
5291 } |
4802 } |
5292 } |
4803 } |
5293 else { |
4804 else { |
5294 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "No argument mean remove all file"); |
|
5295 $v_found = true; |
4805 $v_found = true; |
5296 } |
4806 } |
5297 |
4807 |
5298 // ----- Look for deletion |
4808 // ----- Look for deletion |
5299 if ($v_found) |
4809 if ($v_found) |
5300 { |
4810 { |
5301 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' need to be deleted"); |
|
5302 unset($v_header_list[$v_nb_extracted]); |
4811 unset($v_header_list[$v_nb_extracted]); |
5303 } |
4812 } |
5304 else |
4813 else |
5305 { |
4814 { |
5306 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' will not be deleted"); |
|
5307 $v_nb_extracted++; |
4815 $v_nb_extracted++; |
5308 } |
4816 } |
5309 } |
4817 } |
5310 |
4818 |
5311 // ----- Look if something need to be deleted |
4819 // ----- Look if something need to be deleted |
5316 |
4824 |
5317 // ----- Creates a temporary zip archive |
4825 // ----- Creates a temporary zip archive |
5318 $v_temp_zip = new PclZip($v_zip_temp_name); |
4826 $v_temp_zip = new PclZip($v_zip_temp_name); |
5319 |
4827 |
5320 // ----- Open the temporary zip file in write mode |
4828 // ----- Open the temporary zip file in write mode |
5321 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary write mode"); |
|
5322 if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) { |
4829 if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) { |
5323 $this->privCloseFd(); |
4830 $this->privCloseFd(); |
5324 |
4831 |
5325 // ----- Return |
4832 // ----- Return |
5326 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5327 return $v_result; |
4833 return $v_result; |
5328 } |
4834 } |
5329 |
4835 |
5330 // ----- Look which file need to be kept |
4836 // ----- Look which file need to be kept |
5331 for ($i=0; $i<sizeof($v_header_list); $i++) { |
4837 for ($i=0; $i<sizeof($v_header_list); $i++) { |
5332 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Keep entry index '$i' : '".$v_header_list[$i]['filename']."'"); |
|
5333 |
4838 |
5334 // ----- Calculate the position of the header |
4839 // ----- Calculate the position of the header |
5335 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset='". $v_header_list[$i]['offset']."'"); |
|
5336 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); |
|
5337 @rewind($this->zip_fd); |
4840 @rewind($this->zip_fd); |
5338 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); |
|
5339 if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { |
4841 if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { |
5340 // ----- Close the zip file |
4842 // ----- Close the zip file |
5341 $this->privCloseFd(); |
4843 $this->privCloseFd(); |
5342 $v_temp_zip->privCloseFd(); |
4844 $v_temp_zip->privCloseFd(); |
5343 @unlink($v_zip_temp_name); |
4845 @unlink($v_zip_temp_name); |
5344 |
4846 |
5345 // ----- Error log |
4847 // ----- Error log |
5346 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
4848 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
5347 |
4849 |
5348 // ----- Return |
4850 // ----- Return |
5349 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
5350 return PclZip::errorCode(); |
4851 return PclZip::errorCode(); |
5351 } |
4852 } |
5352 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); |
|
5353 |
4853 |
5354 // ----- Read the file header |
4854 // ----- Read the file header |
5355 $v_local_header = array(); |
4855 $v_local_header = array(); |
5356 if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) { |
4856 if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) { |
5357 // ----- Close the zip file |
4857 // ----- Close the zip file |
5358 $this->privCloseFd(); |
4858 $this->privCloseFd(); |
5359 $v_temp_zip->privCloseFd(); |
4859 $v_temp_zip->privCloseFd(); |
5360 @unlink($v_zip_temp_name); |
4860 @unlink($v_zip_temp_name); |
5361 |
4861 |
5362 // ----- Return |
4862 // ----- Return |
5363 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5364 return $v_result; |
4863 return $v_result; |
5365 } |
4864 } |
5366 |
4865 |
5367 // ----- Check that local file header is same as central file header |
4866 // ----- Check that local file header is same as central file header |
5368 if ($this->privCheckFileHeaders($v_local_header, |
4867 if ($this->privCheckFileHeaders($v_local_header, |
5369 $v_header_list[$i]) != 1) { |
4868 $v_header_list[$i]) != 1) { |
5370 // TBC |
4869 // TBC |
5371 } |
4870 } |
5377 $this->privCloseFd(); |
4876 $this->privCloseFd(); |
5378 $v_temp_zip->privCloseFd(); |
4877 $v_temp_zip->privCloseFd(); |
5379 @unlink($v_zip_temp_name); |
4878 @unlink($v_zip_temp_name); |
5380 |
4879 |
5381 // ----- Return |
4880 // ----- Return |
5382 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5383 return $v_result; |
4881 return $v_result; |
5384 } |
4882 } |
5385 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset for this file is '".$v_header_list[$i]['offset']."'"); |
|
5386 |
4883 |
5387 // ----- Read/write the data block |
4884 // ----- Read/write the data block |
5388 if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) { |
4885 if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) { |
5389 // ----- Close the zip file |
4886 // ----- Close the zip file |
5390 $this->privCloseFd(); |
4887 $this->privCloseFd(); |
5391 $v_temp_zip->privCloseFd(); |
4888 $v_temp_zip->privCloseFd(); |
5392 @unlink($v_zip_temp_name); |
4889 @unlink($v_zip_temp_name); |
5393 |
4890 |
5394 // ----- Return |
4891 // ----- Return |
5395 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5396 return $v_result; |
4892 return $v_result; |
5397 } |
4893 } |
5398 } |
4894 } |
5399 |
4895 |
5400 // ----- Store the offset of the central dir |
4896 // ----- Store the offset of the central dir |
5401 $v_offset = @ftell($v_temp_zip->zip_fd); |
4897 $v_offset = @ftell($v_temp_zip->zip_fd); |
5402 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "New offset of central dir : $v_offset"); |
|
5403 |
4898 |
5404 // ----- Re-Create the Central Dir files header |
4899 // ----- Re-Create the Central Dir files header |
5405 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the new central directory"); |
|
5406 for ($i=0; $i<sizeof($v_header_list); $i++) { |
4900 for ($i=0; $i<sizeof($v_header_list); $i++) { |
5407 // ----- Create the file header |
4901 // ----- Create the file header |
5408 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset of file : ".$v_header_list[$i]['offset']); |
|
5409 if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
4902 if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
5410 $v_temp_zip->privCloseFd(); |
4903 $v_temp_zip->privCloseFd(); |
5411 $this->privCloseFd(); |
4904 $this->privCloseFd(); |
5412 @unlink($v_zip_temp_name); |
4905 @unlink($v_zip_temp_name); |
5413 |
4906 |
5414 // ----- Return |
4907 // ----- Return |
5415 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5416 return $v_result; |
4908 return $v_result; |
5417 } |
4909 } |
5418 |
4910 |
5419 // ----- Transform the header to a 'usable' info |
4911 // ----- Transform the header to a 'usable' info |
5420 $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
4912 $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
5421 } |
4913 } |
5422 |
4914 |
5423 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the central directory footer"); |
|
5424 |
4915 |
5425 // ----- Zip file comment |
4916 // ----- Zip file comment |
5426 $v_comment = ''; |
4917 $v_comment = ''; |
5427 if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
4918 if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
5428 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
4919 $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
5497 // -------------------------------------------------------------------------------- |
4984 // -------------------------------------------------------------------------------- |
5498 function privDirCheck($p_dir, $p_is_dir=false) |
4985 function privDirCheck($p_dir, $p_is_dir=false) |
5499 { |
4986 { |
5500 $v_result = 1; |
4987 $v_result = 1; |
5501 |
4988 |
5502 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDirCheck", "entry='$p_dir', is_dir='".($p_is_dir?"true":"false")."'"); |
|
5503 |
4989 |
5504 // ----- Remove the final '/' |
4990 // ----- Remove the final '/' |
5505 if (($p_is_dir) && (substr($p_dir, -1)=='/')) |
4991 if (($p_is_dir) && (substr($p_dir, -1)=='/')) |
5506 { |
4992 { |
5507 $p_dir = substr($p_dir, 0, strlen($p_dir)-1); |
4993 $p_dir = substr($p_dir, 0, strlen($p_dir)-1); |
5508 } |
4994 } |
5509 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for entry '$p_dir'"); |
|
5510 |
4995 |
5511 // ----- Check the directory availability |
4996 // ----- Check the directory availability |
5512 if ((is_dir($p_dir)) || ($p_dir == "")) |
4997 if ((is_dir($p_dir)) || ($p_dir == "")) |
5513 { |
4998 { |
5514 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, "'$p_dir' is a directory"); |
|
5515 return 1; |
4999 return 1; |
5516 } |
5000 } |
5517 |
5001 |
5518 // ----- Extract parent directory |
5002 // ----- Extract parent directory |
5519 $p_parent_dir = dirname($p_dir); |
5003 $p_parent_dir = dirname($p_dir); |
5520 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Parent directory is '$p_parent_dir'"); |
|
5521 |
5004 |
5522 // ----- Just a check |
5005 // ----- Just a check |
5523 if ($p_parent_dir != $p_dir) |
5006 if ($p_parent_dir != $p_dir) |
5524 { |
5007 { |
5525 // ----- Look for parent directory |
5008 // ----- Look for parent directory |
5526 if ($p_parent_dir != "") |
5009 if ($p_parent_dir != "") |
5527 { |
5010 { |
5528 if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) |
5011 if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) |
5529 { |
5012 { |
5530 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5531 return $v_result; |
5013 return $v_result; |
5532 } |
5014 } |
5533 } |
5015 } |
5534 } |
5016 } |
5535 |
5017 |
5536 // ----- Create the directory |
5018 // ----- Create the directory |
5537 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Create directory '$p_dir'"); |
|
5538 if (!@mkdir($p_dir, 0777)) |
5019 if (!@mkdir($p_dir, 0777)) |
5539 { |
5020 { |
5540 // ----- Error log |
5021 // ----- Error log |
5541 PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); |
5022 PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); |
5542 |
5023 |
5543 // ----- Return |
5024 // ----- Return |
5544 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
5545 return PclZip::errorCode(); |
5025 return PclZip::errorCode(); |
5546 } |
5026 } |
5547 |
5027 |
5548 // ----- Return |
5028 // ----- Return |
5549 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result, "Directory '$p_dir' created"); |
|
5550 return $v_result; |
5029 return $v_result; |
5551 } |
5030 } |
5552 // -------------------------------------------------------------------------------- |
5031 // -------------------------------------------------------------------------------- |
5553 |
5032 |
5554 // -------------------------------------------------------------------------------- |
5033 // -------------------------------------------------------------------------------- |
5558 // Parameters : |
5037 // Parameters : |
5559 // Return Values : |
5038 // Return Values : |
5560 // -------------------------------------------------------------------------------- |
5039 // -------------------------------------------------------------------------------- |
5561 function privMerge(&$p_archive_to_add) |
5040 function privMerge(&$p_archive_to_add) |
5562 { |
5041 { |
5563 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privMerge", "archive='".$p_archive_to_add->zipname."'"); |
|
5564 $v_result=1; |
5042 $v_result=1; |
5565 |
5043 |
5566 // ----- Look if the archive_to_add exists |
5044 // ----- Look if the archive_to_add exists |
5567 if (!is_file($p_archive_to_add->zipname)) |
5045 if (!is_file($p_archive_to_add->zipname)) |
5568 { |
5046 { |
5569 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to add does not exist. End of merge."); |
|
5570 |
5047 |
5571 // ----- Nothing to merge, so merge is a success |
5048 // ----- Nothing to merge, so merge is a success |
5572 $v_result = 1; |
5049 $v_result = 1; |
5573 |
5050 |
5574 // ----- Return |
5051 // ----- Return |
5575 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5576 return $v_result; |
5052 return $v_result; |
5577 } |
5053 } |
5578 |
5054 |
5579 // ----- Look if the archive exists |
5055 // ----- Look if the archive exists |
5580 if (!is_file($this->zipname)) |
5056 if (!is_file($this->zipname)) |
5581 { |
5057 { |
5582 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, duplicate the archive_to_add."); |
|
5583 |
5058 |
5584 // ----- Do a duplicate |
5059 // ----- Do a duplicate |
5585 $v_result = $this->privDuplicate($p_archive_to_add->zipname); |
5060 $v_result = $this->privDuplicate($p_archive_to_add->zipname); |
5586 |
5061 |
5587 // ----- Return |
5062 // ----- Return |
5588 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5589 return $v_result; |
5063 return $v_result; |
5590 } |
5064 } |
5591 |
5065 |
5592 // ----- Open the zip file |
5066 // ----- Open the zip file |
5593 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); |
|
5594 if (($v_result=$this->privOpenFd('rb')) != 1) |
5067 if (($v_result=$this->privOpenFd('rb')) != 1) |
5595 { |
5068 { |
5596 // ----- Return |
5069 // ----- Return |
5597 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5598 return $v_result; |
5070 return $v_result; |
5599 } |
5071 } |
5600 |
5072 |
5601 // ----- Read the central directory informations |
5073 // ----- Read the central directory informations |
5602 $v_central_dir = array(); |
5074 $v_central_dir = array(); |
5603 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
5075 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
5604 { |
5076 { |
5605 $this->privCloseFd(); |
5077 $this->privCloseFd(); |
5606 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5607 return $v_result; |
5078 return $v_result; |
5608 } |
5079 } |
5609 |
5080 |
5610 // ----- Go to beginning of File |
5081 // ----- Go to beginning of File |
5611 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'"); |
|
5612 @rewind($this->zip_fd); |
5082 @rewind($this->zip_fd); |
5613 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'"); |
|
5614 |
5083 |
5615 // ----- Open the archive_to_add file |
5084 // ----- Open the archive_to_add file |
5616 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open archive_to_add in binary read mode"); |
|
5617 if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) |
5085 if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) |
5618 { |
5086 { |
5619 $this->privCloseFd(); |
5087 $this->privCloseFd(); |
5620 |
5088 |
5621 // ----- Return |
5089 // ----- Return |
5622 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5623 return $v_result; |
5090 return $v_result; |
5624 } |
5091 } |
5625 |
5092 |
5626 // ----- Read the central directory informations |
5093 // ----- Read the central directory informations |
5627 $v_central_dir_to_add = array(); |
5094 $v_central_dir_to_add = array(); |
5628 if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) |
5095 if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) |
5629 { |
5096 { |
5630 $this->privCloseFd(); |
5097 $this->privCloseFd(); |
5631 $p_archive_to_add->privCloseFd(); |
5098 $p_archive_to_add->privCloseFd(); |
5632 |
5099 |
5633 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5634 return $v_result; |
5100 return $v_result; |
5635 } |
5101 } |
5636 |
5102 |
5637 // ----- Go to beginning of File |
5103 // ----- Go to beginning of File |
5638 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'"); |
|
5639 @rewind($p_archive_to_add->zip_fd); |
5104 @rewind($p_archive_to_add->zip_fd); |
5640 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'"); |
|
5641 |
5105 |
5642 // ----- Creates a temporay file |
5106 // ----- Creates a temporay file |
5643 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
5107 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
5644 |
5108 |
5645 // ----- Open the temporary file in write mode |
5109 // ----- Open the temporary file in write mode |
5646 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); |
|
5647 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
5110 if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
5648 { |
5111 { |
5649 $this->privCloseFd(); |
5112 $this->privCloseFd(); |
5650 $p_archive_to_add->privCloseFd(); |
5113 $p_archive_to_add->privCloseFd(); |
5651 |
5114 |
5652 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
5115 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
5653 |
5116 |
5654 // ----- Return |
5117 // ----- Return |
5655 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
5656 return PclZip::errorCode(); |
5118 return PclZip::errorCode(); |
5657 } |
5119 } |
5658 |
5120 |
5659 // ----- Copy the files from the archive to the temporary file |
5121 // ----- Copy the files from the archive to the temporary file |
5660 // TBC : Here I should better append the file and go back to erase the central dir |
5122 // TBC : Here I should better append the file and go back to erase the central dir |
5661 $v_size = $v_central_dir['offset']; |
5123 $v_size = $v_central_dir['offset']; |
5662 while ($v_size != 0) |
5124 while ($v_size != 0) |
5663 { |
5125 { |
5664 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
5126 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
5665 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); |
|
5666 $v_buffer = fread($this->zip_fd, $v_read_size); |
5127 $v_buffer = fread($this->zip_fd, $v_read_size); |
5667 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
5128 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
5668 $v_size -= $v_read_size; |
5129 $v_size -= $v_read_size; |
5669 } |
5130 } |
5670 |
5131 |
5671 // ----- Copy the files from the archive_to_add into the temporary file |
5132 // ----- Copy the files from the archive_to_add into the temporary file |
5672 $v_size = $v_central_dir_to_add['offset']; |
5133 $v_size = $v_central_dir_to_add['offset']; |
5673 while ($v_size != 0) |
5134 while ($v_size != 0) |
5674 { |
5135 { |
5675 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
5136 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
5676 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); |
|
5677 $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); |
5137 $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); |
5678 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
5138 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
5679 $v_size -= $v_read_size; |
5139 $v_size -= $v_read_size; |
5680 } |
5140 } |
5681 |
5141 |
5682 // ----- Store the offset of the central dir |
5142 // ----- Store the offset of the central dir |
5683 $v_offset = @ftell($v_zip_temp_fd); |
5143 $v_offset = @ftell($v_zip_temp_fd); |
5684 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset"); |
|
5685 |
5144 |
5686 // ----- Copy the block of file headers from the old archive |
5145 // ----- Copy the block of file headers from the old archive |
5687 $v_size = $v_central_dir['size']; |
5146 $v_size = $v_central_dir['size']; |
5688 while ($v_size != 0) |
5147 while ($v_size != 0) |
5689 { |
5148 { |
5690 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
5149 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
5691 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); |
|
5692 $v_buffer = @fread($this->zip_fd, $v_read_size); |
5150 $v_buffer = @fread($this->zip_fd, $v_read_size); |
5693 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
5151 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
5694 $v_size -= $v_read_size; |
5152 $v_size -= $v_read_size; |
5695 } |
5153 } |
5696 |
5154 |
5697 // ----- Copy the block of file headers from the archive_to_add |
5155 // ----- Copy the block of file headers from the archive_to_add |
5698 $v_size = $v_central_dir_to_add['size']; |
5156 $v_size = $v_central_dir_to_add['size']; |
5699 while ($v_size != 0) |
5157 while ($v_size != 0) |
5700 { |
5158 { |
5701 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
5159 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
5702 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); |
|
5703 $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); |
5160 $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); |
5704 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
5161 @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
5705 $v_size -= $v_read_size; |
5162 $v_size -= $v_read_size; |
5706 } |
5163 } |
5707 |
5164 |
5767 // Parameters : |
5222 // Parameters : |
5768 // Return Values : |
5223 // Return Values : |
5769 // -------------------------------------------------------------------------------- |
5224 // -------------------------------------------------------------------------------- |
5770 function privDuplicate($p_archive_filename) |
5225 function privDuplicate($p_archive_filename) |
5771 { |
5226 { |
5772 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDuplicate", "archive_filename='$p_archive_filename'"); |
|
5773 $v_result=1; |
5227 $v_result=1; |
5774 |
5228 |
5775 // ----- Look if the $p_archive_filename exists |
5229 // ----- Look if the $p_archive_filename exists |
5776 if (!is_file($p_archive_filename)) |
5230 if (!is_file($p_archive_filename)) |
5777 { |
5231 { |
5778 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to duplicate does not exist. End of duplicate."); |
|
5779 |
5232 |
5780 // ----- Nothing to duplicate, so duplicate is a success. |
5233 // ----- Nothing to duplicate, so duplicate is a success. |
5781 $v_result = 1; |
5234 $v_result = 1; |
5782 |
5235 |
5783 // ----- Return |
5236 // ----- Return |
5784 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5785 return $v_result; |
5237 return $v_result; |
5786 } |
5238 } |
5787 |
5239 |
5788 // ----- Open the zip file |
5240 // ----- Open the zip file |
5789 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); |
|
5790 if (($v_result=$this->privOpenFd('wb')) != 1) |
5241 if (($v_result=$this->privOpenFd('wb')) != 1) |
5791 { |
5242 { |
5792 // ----- Return |
5243 // ----- Return |
5793 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
5794 return $v_result; |
5244 return $v_result; |
5795 } |
5245 } |
5796 |
5246 |
5797 // ----- Open the temporary file in write mode |
5247 // ----- Open the temporary file in write mode |
5798 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); |
|
5799 if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) |
5248 if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) |
5800 { |
5249 { |
5801 $this->privCloseFd(); |
5250 $this->privCloseFd(); |
5802 |
5251 |
5803 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); |
5252 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); |
5804 |
5253 |
5805 // ----- Return |
5254 // ----- Return |
5806 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); |
|
5807 return PclZip::errorCode(); |
5255 return PclZip::errorCode(); |
5808 } |
5256 } |
5809 |
5257 |
5810 // ----- Copy the files from the archive to the temporary file |
5258 // ----- Copy the files from the archive to the temporary file |
5811 // TBC : Here I should better append the file and go back to erase the central dir |
5259 // TBC : Here I should better append the file and go back to erase the central dir |
5812 $v_size = filesize($p_archive_filename); |
5260 $v_size = filesize($p_archive_filename); |
5813 while ($v_size != 0) |
5261 while ($v_size != 0) |
5814 { |
5262 { |
5815 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
5263 $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
5816 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read $v_read_size bytes"); |
|
5817 $v_buffer = fread($v_zip_temp_fd, $v_read_size); |
5264 $v_buffer = fread($v_zip_temp_fd, $v_read_size); |
5818 @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
5265 @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
5819 $v_size -= $v_read_size; |
5266 $v_size -= $v_read_size; |
5820 } |
5267 } |
5821 |
5268 |
6124 // 3 : src & dest gzip |
5544 // 3 : src & dest gzip |
6125 // Return Values : |
5545 // Return Values : |
6126 // -------------------------------------------------------------------------------- |
5546 // -------------------------------------------------------------------------------- |
6127 function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) |
5547 function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) |
6128 { |
5548 { |
6129 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilCopyBlock", "size=$p_size, mode=$p_mode"); |
|
6130 $v_result = 1; |
5549 $v_result = 1; |
6131 |
5550 |
6132 if ($p_mode==0) |
5551 if ($p_mode==0) |
6133 { |
5552 { |
6134 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset before read :".(@ftell($p_src))); |
|
6135 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset before write :".(@ftell($p_dest))); |
|
6136 while ($p_size != 0) |
5553 while ($p_size != 0) |
6137 { |
5554 { |
6138 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
5555 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
6139 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); |
|
6140 $v_buffer = @fread($p_src, $v_read_size); |
5556 $v_buffer = @fread($p_src, $v_read_size); |
6141 @fwrite($p_dest, $v_buffer, $v_read_size); |
5557 @fwrite($p_dest, $v_buffer, $v_read_size); |
6142 $p_size -= $v_read_size; |
5558 $p_size -= $v_read_size; |
6143 } |
5559 } |
6144 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset after read :".(@ftell($p_src))); |
|
6145 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset after write :".(@ftell($p_dest))); |
|
6146 } |
5560 } |
6147 else if ($p_mode==1) |
5561 else if ($p_mode==1) |
6148 { |
5562 { |
6149 while ($p_size != 0) |
5563 while ($p_size != 0) |
6150 { |
5564 { |
6151 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
5565 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
6152 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); |
|
6153 $v_buffer = @gzread($p_src, $v_read_size); |
5566 $v_buffer = @gzread($p_src, $v_read_size); |
6154 @fwrite($p_dest, $v_buffer, $v_read_size); |
5567 @fwrite($p_dest, $v_buffer, $v_read_size); |
6155 $p_size -= $v_read_size; |
5568 $p_size -= $v_read_size; |
6156 } |
5569 } |
6157 } |
5570 } |
6158 else if ($p_mode==2) |
5571 else if ($p_mode==2) |
6159 { |
5572 { |
6160 while ($p_size != 0) |
5573 while ($p_size != 0) |
6161 { |
5574 { |
6162 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
5575 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
6163 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); |
|
6164 $v_buffer = @fread($p_src, $v_read_size); |
5576 $v_buffer = @fread($p_src, $v_read_size); |
6165 @gzwrite($p_dest, $v_buffer, $v_read_size); |
5577 @gzwrite($p_dest, $v_buffer, $v_read_size); |
6166 $p_size -= $v_read_size; |
5578 $p_size -= $v_read_size; |
6167 } |
5579 } |
6168 } |
5580 } |
6169 else if ($p_mode==3) |
5581 else if ($p_mode==3) |
6170 { |
5582 { |
6171 while ($p_size != 0) |
5583 while ($p_size != 0) |
6172 { |
5584 { |
6173 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
5585 $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
6174 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); |
|
6175 $v_buffer = @gzread($p_src, $v_read_size); |
5586 $v_buffer = @gzread($p_src, $v_read_size); |
6176 @gzwrite($p_dest, $v_buffer, $v_read_size); |
5587 @gzwrite($p_dest, $v_buffer, $v_read_size); |
6177 $p_size -= $v_read_size; |
5588 $p_size -= $v_read_size; |
6178 } |
5589 } |
6179 } |
5590 } |
6180 |
5591 |
6181 // ----- Return |
5592 // ----- Return |
6182 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); |
|
6183 return $v_result; |
5593 return $v_result; |
6184 } |
5594 } |
6185 // -------------------------------------------------------------------------------- |
5595 // -------------------------------------------------------------------------------- |
6186 |
5596 |
6187 // -------------------------------------------------------------------------------- |
5597 // -------------------------------------------------------------------------------- |