PclZip Class Reference

List of all members.

Public Member Functions

Public Attributes


Detailed Description

Definition at line 190 of file pclzip.lib.php.


Member Function Documentation

PclZip::add ( p_filelist  ) 

Definition at line 454 of file pclzip.lib.php.

00455   {
00456     $v_result=1;
00457 
00458     // ----- Reset the error handler
00459     $this->privErrorReset();
00460 
00461     // ----- Set default values
00462     $v_options = array();
00463     $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
00464 
00465     // ----- Look for variable options arguments
00466     $v_size = func_num_args();
00467 
00468     // ----- Look for arguments
00469     if ($v_size > 1) {
00470       // ----- Get the arguments
00471       $v_arg_list = func_get_args();
00472 
00473       // ----- Remove form the options list the first argument
00474       array_shift($v_arg_list);
00475       $v_size--;
00476 
00477       // ----- Look for first arg
00478       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
00479 
00480         // ----- Parse the options
00481         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
00482                                             array (PCLZIP_OPT_REMOVE_PATH => 'optional',
00483                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
00484                                                    PCLZIP_OPT_ADD_PATH => 'optional',
00485                                                    PCLZIP_CB_PRE_ADD => 'optional',
00486                                                    PCLZIP_CB_POST_ADD => 'optional',
00487                                                    PCLZIP_OPT_NO_COMPRESSION => 'optional',
00488                                                    PCLZIP_OPT_COMMENT => 'optional',
00489                                                    PCLZIP_OPT_ADD_COMMENT => 'optional',
00490                                                    PCLZIP_OPT_PREPEND_COMMENT => 'optional',
00491                                                    PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
00492                                                    PCLZIP_OPT_TEMP_FILE_ON => 'optional',
00493                                                    PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
00494                                                    //, PCLZIP_OPT_CRYPT => 'optional'
00495                                                                                                    ));
00496         if ($v_result != 1) {
00497           return 0;
00498         }
00499       }
00500 
00501       // ----- Look for 2 args
00502       // Here we need to support the first historic synopsis of the
00503       // method.
00504       else {
00505 
00506         // ----- Get the first argument
00507         $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
00508 
00509         // ----- Look for the optional second argument
00510         if ($v_size == 2) {
00511           $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
00512         }
00513         else if ($v_size > 2) {
00514           // ----- Error log
00515           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
00516 
00517           // ----- Return
00518           return 0;
00519         }
00520       }
00521     }
00522 
00523     // ----- Look for default option values
00524     $this->privOptionDefaultThreshold($v_options);
00525 
00526     // ----- Init
00527     $v_string_list = array();
00528     $v_att_list = array();
00529     $v_filedescr_list = array();
00530     $p_result_list = array();
00531     
00532     // ----- Look if the $p_filelist is really an array
00533     if (is_array($p_filelist)) {
00534     
00535       // ----- Look if the first element is also an array
00536       //       This will mean that this is a file description entry
00537       if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
00538         $v_att_list = $p_filelist;
00539       }
00540       
00541       // ----- The list is a list of string names
00542       else {
00543         $v_string_list = $p_filelist;
00544       }
00545     }
00546 
00547     // ----- Look if the $p_filelist is a string
00548     else if (is_string($p_filelist)) {
00549       // ----- Create a list from the string
00550       $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
00551     }
00552 
00553     // ----- Invalid variable type for $p_filelist
00554     else {
00555       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
00556       return 0;
00557     }
00558     
00559     // ----- Reformat the string list
00560     if (sizeof($v_string_list) != 0) {
00561       foreach ($v_string_list as $v_string) {
00562         $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
00563       }
00564     }
00565     
00566     // ----- For each file in the list check the attributes
00567     $v_supported_attributes
00568     = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
00569              ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
00570              ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
00571              ,PCLZIP_ATT_FILE_MTIME => 'optional'
00572              ,PCLZIP_ATT_FILE_CONTENT => 'optional'
00573              ,PCLZIP_ATT_FILE_COMMENT => 'optional'
00574                                                 );
00575     foreach ($v_att_list as $v_entry) {
00576       $v_result = $this->privFileDescrParseAtt($v_entry,
00577                                                $v_filedescr_list[],
00578                                                $v_options,
00579                                                $v_supported_attributes);
00580       if ($v_result != 1) {
00581         return 0;
00582       }
00583     }
00584 
00585     // ----- Expand the filelist (expand directories)
00586     $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
00587     if ($v_result != 1) {
00588       return 0;
00589     }
00590 
00591     // ----- Call the create fct
00592     $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
00593     if ($v_result != 1) {
00594       return 0;
00595     }
00596 
00597     // ----- Return
00598     return $p_result_list;
00599   }

PclZip::create ( p_filelist  ) 

Definition at line 271 of file pclzip.lib.php.

00272   {
00273     $v_result=1;
00274 
00275     // ----- Reset the error handler
00276     $this->privErrorReset();
00277 
00278     // ----- Set default values
00279     $v_options = array();
00280     $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
00281 
00282     // ----- Look for variable options arguments
00283     $v_size = func_num_args();
00284 
00285     // ----- Look for arguments
00286     if ($v_size > 1) {
00287       // ----- Get the arguments
00288       $v_arg_list = func_get_args();
00289 
00290       // ----- Remove from the options list the first argument
00291       array_shift($v_arg_list);
00292       $v_size--;
00293 
00294       // ----- Look for first arg
00295       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
00296 
00297         // ----- Parse the options
00298         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
00299                                             array (PCLZIP_OPT_REMOVE_PATH => 'optional',
00300                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
00301                                                    PCLZIP_OPT_ADD_PATH => 'optional',
00302                                                    PCLZIP_CB_PRE_ADD => 'optional',
00303                                                    PCLZIP_CB_POST_ADD => 'optional',
00304                                                    PCLZIP_OPT_NO_COMPRESSION => 'optional',
00305                                                    PCLZIP_OPT_COMMENT => 'optional',
00306                                                    PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
00307                                                    PCLZIP_OPT_TEMP_FILE_ON => 'optional',
00308                                                    PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
00309                                                    //, PCLZIP_OPT_CRYPT => 'optional'
00310                                              ));
00311         if ($v_result != 1) {
00312           return 0;
00313         }
00314       }
00315 
00316       // ----- Look for 2 args
00317       // Here we need to support the first historic synopsis of the
00318       // method.
00319       else {
00320 
00321         // ----- Get the first argument
00322         $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
00323 
00324         // ----- Look for the optional second argument
00325         if ($v_size == 2) {
00326           $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
00327         }
00328         else if ($v_size > 2) {
00329           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
00330                                        "Invalid number / type of arguments");
00331           return 0;
00332         }
00333       }
00334     }
00335     
00336     // ----- Look for default option values
00337     $this->privOptionDefaultThreshold($v_options);
00338 
00339     // ----- Init
00340     $v_string_list = array();
00341     $v_att_list = array();
00342     $v_filedescr_list = array();
00343     $p_result_list = array();
00344     
00345     // ----- Look if the $p_filelist is really an array
00346     if (is_array($p_filelist)) {
00347     
00348       // ----- Look if the first element is also an array
00349       //       This will mean that this is a file description entry
00350       if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
00351         $v_att_list = $p_filelist;
00352       }
00353       
00354       // ----- The list is a list of string names
00355       else {
00356         $v_string_list = $p_filelist;
00357       }
00358     }
00359 
00360     // ----- Look if the $p_filelist is a string
00361     else if (is_string($p_filelist)) {
00362       // ----- Create a list from the string
00363       $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
00364     }
00365 
00366     // ----- Invalid variable type for $p_filelist
00367     else {
00368       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
00369       return 0;
00370     }
00371     
00372     // ----- Reformat the string list
00373     if (sizeof($v_string_list) != 0) {
00374       foreach ($v_string_list as $v_string) {
00375         if ($v_string != '') {
00376           $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
00377         }
00378         else {
00379         }
00380       }
00381     }
00382     
00383     // ----- For each file in the list check the attributes
00384     $v_supported_attributes
00385     = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
00386              ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
00387              ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
00388              ,PCLZIP_ATT_FILE_MTIME => 'optional'
00389              ,PCLZIP_ATT_FILE_CONTENT => 'optional'
00390              ,PCLZIP_ATT_FILE_COMMENT => 'optional'
00391                                                 );
00392     foreach ($v_att_list as $v_entry) {
00393       $v_result = $this->privFileDescrParseAtt($v_entry,
00394                                                $v_filedescr_list[],
00395                                                $v_options,
00396                                                $v_supported_attributes);
00397       if ($v_result != 1) {
00398         return 0;
00399       }
00400     }
00401 
00402     // ----- Expand the filelist (expand directories)
00403     $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
00404     if ($v_result != 1) {
00405       return 0;
00406     }
00407 
00408     // ----- Call the create fct
00409     $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
00410     if ($v_result != 1) {
00411       return 0;
00412     }
00413 
00414     // ----- Return
00415     return $p_result_list;
00416   }

PclZip::delete (  ) 

Definition at line 1006 of file pclzip.lib.php.

01007   {
01008     $v_result=1;
01009 
01010     // ----- Reset the error handler
01011     $this->privErrorReset();
01012 
01013     // ----- Check archive
01014     if (!$this->privCheckFormat()) {
01015       return(0);
01016     }
01017 
01018     // ----- Set default values
01019     $v_options = array();
01020 
01021     // ----- Look for variable options arguments
01022     $v_size = func_num_args();
01023 
01024     // ----- Look for arguments
01025     if ($v_size > 0) {
01026       // ----- Get the arguments
01027       $v_arg_list = func_get_args();
01028 
01029       // ----- Parse the options
01030       $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
01031                                         array (PCLZIP_OPT_BY_NAME => 'optional',
01032                                                PCLZIP_OPT_BY_EREG => 'optional',
01033                                                PCLZIP_OPT_BY_PREG => 'optional',
01034                                                PCLZIP_OPT_BY_INDEX => 'optional' ));
01035       if ($v_result != 1) {
01036           return 0;
01037       }
01038     }
01039 
01040     // ----- Magic quotes trick
01041     $this->privDisableMagicQuotes();
01042 
01043     // ----- Call the delete fct
01044     $v_list = array();
01045     if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
01046       $this->privSwapBackMagicQuotes();
01047       unset($v_list);
01048       return(0);
01049     }
01050 
01051     // ----- Magic quotes trick
01052     $this->privSwapBackMagicQuotes();
01053 
01054     // ----- Return
01055     return $v_list;
01056   }

PclZip::deleteByIndex ( p_index  ) 

Definition at line 1065 of file pclzip.lib.php.

01066   {
01067     
01068     $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
01069 
01070     // ----- Return
01071     return $p_list;
01072   }

PclZip::duplicate ( p_archive  ) 

Definition at line 1162 of file pclzip.lib.php.

01163   {
01164     $v_result = 1;
01165 
01166     // ----- Reset the error handler
01167     $this->privErrorReset();
01168 
01169     // ----- Look if the $p_archive is a PclZip object
01170     if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
01171     {
01172 
01173       // ----- Duplicate the archive
01174       $v_result = $this->privDuplicate($p_archive->zipname);
01175     }
01176 
01177     // ----- Look if the $p_archive is a string (so a filename)
01178     else if (is_string($p_archive))
01179     {
01180 
01181       // ----- Check that $p_archive is a valid zip file
01182       // TBC : Should also check the archive format
01183       if (!is_file($p_archive)) {
01184         // ----- Error log
01185         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
01186         $v_result = PCLZIP_ERR_MISSING_FILE;
01187       }
01188       else {
01189         // ----- Duplicate the archive
01190         $v_result = $this->privDuplicate($p_archive);
01191       }
01192     }
01193 
01194     // ----- Invalid variable
01195     else
01196     {
01197       // ----- Error log
01198       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
01199       $v_result = PCLZIP_ERR_INVALID_PARAMETER;
01200     }
01201 
01202     // ----- Return
01203     return $v_result;
01204   }

PclZip::errorCode (  ) 

Definition at line 1272 of file pclzip.lib.php.

Referenced by privDeleteByRule(), and privDirCheck().

01273   {
01274     if (PCLZIP_ERROR_EXTERNAL == 1) {
01275       return(PclErrorCode());
01276     }
01277     else {
01278       return($this->error_code);
01279     }
01280   }

PclZip::errorInfo ( p_full = false  ) 

Definition at line 1334 of file pclzip.lib.php.

01335   {
01336     if (PCLZIP_ERROR_EXTERNAL == 1) {
01337       return(PclErrorString());
01338     }
01339     else {
01340       if ($p_full) {
01341         return($this->errorName(true)." : ".$this->error_string);
01342       }
01343       else {
01344         return($this->error_string." [code ".$this->error_code."]");
01345       }
01346     }
01347   }

PclZip::errorName ( p_with_code = false  ) 

Definition at line 1288 of file pclzip.lib.php.

01289   {
01290     $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
01291                       PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
01292                       PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
01293                       PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
01294                       PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
01295                       PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
01296                       PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
01297                       PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
01298                       PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
01299                       PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
01300                       PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
01301                       PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
01302                       PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
01303                       PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
01304                       PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
01305                       PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
01306                       PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
01307                       PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
01308                       PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
01309                       ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
01310                       ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
01311                     );
01312 
01313     if (isset($v_name[$this->error_code])) {
01314       $v_value = $v_name[$this->error_code];
01315     }
01316     else {
01317       $v_value = 'NoName';
01318     }
01319 
01320     if ($p_with_code) {
01321       return($v_value.' ('.$this->error_code.')');
01322     }
01323     else {
01324       return($v_value);
01325     }
01326   }

PclZip::extract (  ) 

Definition at line 700 of file pclzip.lib.php.

00701   {
00702     $v_result=1;
00703 
00704     // ----- Reset the error handler
00705     $this->privErrorReset();
00706 
00707     // ----- Check archive
00708     if (!$this->privCheckFormat()) {
00709       return(0);
00710     }
00711 
00712     // ----- Set default values
00713     $v_options = array();
00714 //    $v_path = "./";
00715     $v_path = '';
00716     $v_remove_path = "";
00717     $v_remove_all_path = false;
00718 
00719     // ----- Look for variable options arguments
00720     $v_size = func_num_args();
00721 
00722     // ----- Default values for option
00723     $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
00724 
00725     // ----- Look for arguments
00726     if ($v_size > 0) {
00727       // ----- Get the arguments
00728       $v_arg_list = func_get_args();
00729 
00730       // ----- Look for first arg
00731       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
00732 
00733         // ----- Parse the options
00734         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
00735                                             array (PCLZIP_OPT_PATH => 'optional',
00736                                                    PCLZIP_OPT_REMOVE_PATH => 'optional',
00737                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
00738                                                    PCLZIP_OPT_ADD_PATH => 'optional',
00739                                                    PCLZIP_CB_PRE_EXTRACT => 'optional',
00740                                                    PCLZIP_CB_POST_EXTRACT => 'optional',
00741                                                    PCLZIP_OPT_SET_CHMOD => 'optional',
00742                                                    PCLZIP_OPT_BY_NAME => 'optional',
00743                                                    PCLZIP_OPT_BY_EREG => 'optional',
00744                                                    PCLZIP_OPT_BY_PREG => 'optional',
00745                                                    PCLZIP_OPT_BY_INDEX => 'optional',
00746                                                    PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
00747                                                    PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
00748                                                    PCLZIP_OPT_REPLACE_NEWER => 'optional'
00749                                                    ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
00750                                                    ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
00751                                                    PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
00752                                                    PCLZIP_OPT_TEMP_FILE_ON => 'optional',
00753                                                    PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
00754                                                                                                     ));
00755         if ($v_result != 1) {
00756           return 0;
00757         }
00758 
00759         // ----- Set the arguments
00760         if (isset($v_options[PCLZIP_OPT_PATH])) {
00761           $v_path = $v_options[PCLZIP_OPT_PATH];
00762         }
00763         if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
00764           $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
00765         }
00766         if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
00767           $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
00768         }
00769         if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
00770           // ----- Check for '/' in last path char
00771           if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
00772             $v_path .= '/';
00773           }
00774           $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
00775         }
00776       }
00777 
00778       // ----- Look for 2 args
00779       // Here we need to support the first historic synopsis of the
00780       // method.
00781       else {
00782 
00783         // ----- Get the first argument
00784         $v_path = $v_arg_list[0];
00785 
00786         // ----- Look for the optional second argument
00787         if ($v_size == 2) {
00788           $v_remove_path = $v_arg_list[1];
00789         }
00790         else if ($v_size > 2) {
00791           // ----- Error log
00792           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
00793 
00794           // ----- Return
00795           return 0;
00796         }
00797       }
00798     }
00799 
00800     // ----- Look for default option values
00801     $this->privOptionDefaultThreshold($v_options);
00802 
00803     // ----- Trace
00804 
00805     // ----- Call the extracting fct
00806     $p_list = array();
00807     $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
00808                                              $v_remove_all_path, $v_options);
00809     if ($v_result < 1) {
00810       unset($p_list);
00811       return(0);
00812     }
00813 
00814     // ----- Return
00815     return $p_list;
00816   }

PclZip::extractByIndex ( p_index  ) 

Definition at line 857 of file pclzip.lib.php.

00858   {
00859     $v_result=1;
00860 
00861     // ----- Reset the error handler
00862     $this->privErrorReset();
00863 
00864     // ----- Check archive
00865     if (!$this->privCheckFormat()) {
00866       return(0);
00867     }
00868 
00869     // ----- Set default values
00870     $v_options = array();
00871 //    $v_path = "./";
00872     $v_path = '';
00873     $v_remove_path = "";
00874     $v_remove_all_path = false;
00875 
00876     // ----- Look for variable options arguments
00877     $v_size = func_num_args();
00878 
00879     // ----- Default values for option
00880     $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
00881 
00882     // ----- Look for arguments
00883     if ($v_size > 1) {
00884       // ----- Get the arguments
00885       $v_arg_list = func_get_args();
00886 
00887       // ----- Remove form the options list the first argument
00888       array_shift($v_arg_list);
00889       $v_size--;
00890 
00891       // ----- Look for first arg
00892       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
00893 
00894         // ----- Parse the options
00895         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
00896                                             array (PCLZIP_OPT_PATH => 'optional',
00897                                                    PCLZIP_OPT_REMOVE_PATH => 'optional',
00898                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
00899                                                    PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
00900                                                    PCLZIP_OPT_ADD_PATH => 'optional',
00901                                                    PCLZIP_CB_PRE_EXTRACT => 'optional',
00902                                                    PCLZIP_CB_POST_EXTRACT => 'optional',
00903                                                    PCLZIP_OPT_SET_CHMOD => 'optional',
00904                                                    PCLZIP_OPT_REPLACE_NEWER => 'optional'
00905                                                    ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
00906                                                    ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
00907                                                    PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
00908                                                    PCLZIP_OPT_TEMP_FILE_ON => 'optional',
00909                                                    PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
00910                                                                                                    ));
00911         if ($v_result != 1) {
00912           return 0;
00913         }
00914 
00915         // ----- Set the arguments
00916         if (isset($v_options[PCLZIP_OPT_PATH])) {
00917           $v_path = $v_options[PCLZIP_OPT_PATH];
00918         }
00919         if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
00920           $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
00921         }
00922         if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
00923           $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
00924         }
00925         if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
00926           // ----- Check for '/' in last path char
00927           if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
00928             $v_path .= '/';
00929           }
00930           $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
00931         }
00932         if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
00933           $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
00934         }
00935         else {
00936         }
00937       }
00938 
00939       // ----- Look for 2 args
00940       // Here we need to support the first historic synopsis of the
00941       // method.
00942       else {
00943 
00944         // ----- Get the first argument
00945         $v_path = $v_arg_list[0];
00946 
00947         // ----- Look for the optional second argument
00948         if ($v_size == 2) {
00949           $v_remove_path = $v_arg_list[1];
00950         }
00951         else if ($v_size > 2) {
00952           // ----- Error log
00953           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
00954 
00955           // ----- Return
00956           return 0;
00957         }
00958       }
00959     }
00960 
00961     // ----- Trace
00962 
00963     // ----- Trick
00964     // Here I want to reuse extractByRule(), so I need to parse the $p_index
00965     // with privParseOptions()
00966     $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
00967     $v_options_trick = array();
00968     $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
00969                                         array (PCLZIP_OPT_BY_INDEX => 'optional' ));
00970     if ($v_result != 1) {
00971         return 0;
00972     }
00973     $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
00974 
00975     // ----- Look for default option values
00976     $this->privOptionDefaultThreshold($v_options);
00977 
00978     // ----- Call the extracting fct
00979     if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
00980         return(0);
00981     }
00982 
00983     // ----- Return
00984     return $p_list;
00985   }

PclZip::listContent (  ) 

Definition at line 643 of file pclzip.lib.php.

00644   {
00645     $v_result=1;
00646 
00647     // ----- Reset the error handler
00648     $this->privErrorReset();
00649 
00650     // ----- Check archive
00651     if (!$this->privCheckFormat()) {
00652       return(0);
00653     }
00654 
00655     // ----- Call the extracting fct
00656     $p_list = array();
00657     if (($v_result = $this->privList($p_list)) != 1)
00658     {
00659       unset($p_list);
00660       return(0);
00661     }
00662 
00663     // ----- Return
00664     return $p_list;
00665   }

PclZip::merge ( p_archive_to_add  ) 

Definition at line 1221 of file pclzip.lib.php.

01222   {
01223     $v_result = 1;
01224 
01225     // ----- Reset the error handler
01226     $this->privErrorReset();
01227 
01228     // ----- Check archive
01229     if (!$this->privCheckFormat()) {
01230       return(0);
01231     }
01232 
01233     // ----- Look if the $p_archive_to_add is a PclZip object
01234     if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
01235     {
01236 
01237       // ----- Merge the archive
01238       $v_result = $this->privMerge($p_archive_to_add);
01239     }
01240 
01241     // ----- Look if the $p_archive_to_add is a string (so a filename)
01242     else if (is_string($p_archive_to_add))
01243     {
01244 
01245       // ----- Create a temporary archive
01246       $v_object_archive = new PclZip($p_archive_to_add);
01247 
01248       // ----- Merge the archive
01249       $v_result = $this->privMerge($v_object_archive);
01250     }
01251 
01252     // ----- Invalid variable
01253     else
01254     {
01255       // ----- Error log
01256       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
01257       $v_result = PCLZIP_ERR_INVALID_PARAMETER;
01258     }
01259 
01260     // ----- Return
01261     return $v_result;
01262   }

PclZip::PclZip ( p_zipname  ) 

Definition at line 215 of file pclzip.lib.php.

Referenced by privDeleteByRule().

00216   {
00217 
00218     // ----- Tests the zlib
00219     if (!function_exists('gzopen'))
00220     {
00221       die('Abort '.basename(__FILE__).' : Missing zlib extensions');
00222     }
00223 
00224     // ----- Set the attributes
00225     $this->zipname = $p_zipname;
00226     $this->zip_fd = 0;
00227     $this->magic_quotes_status = -1;
00228 
00229     // ----- Return
00230     return;
00231   }

PclZip::privAdd ( p_filedescr_list,
&$  p_result_list,
&$  p_options 
)

Definition at line 2159 of file pclzip.lib.php.

Referenced by add().

02160   {
02161     $v_result=1;
02162     $v_list_detail = array();
02163 
02164     // ----- Look if the archive exists or is empty
02165     if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
02166     {
02167 
02168       // ----- Do a create
02169       $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
02170 
02171       // ----- Return
02172       return $v_result;
02173     }
02174     // ----- Magic quotes trick
02175     $this->privDisableMagicQuotes();
02176 
02177     // ----- Open the zip file
02178     if (($v_result=$this->privOpenFd('rb')) != 1)
02179     {
02180       // ----- Magic quotes trick
02181       $this->privSwapBackMagicQuotes();
02182 
02183       // ----- Return
02184       return $v_result;
02185     }
02186 
02187     // ----- Read the central directory informations
02188     $v_central_dir = array();
02189     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
02190     {
02191       $this->privCloseFd();
02192       $this->privSwapBackMagicQuotes();
02193       return $v_result;
02194     }
02195 
02196     // ----- Go to beginning of File
02197     @rewind($this->zip_fd);
02198 
02199     // ----- Creates a temporay file
02200     $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
02201 
02202     // ----- Open the temporary file in write mode
02203     if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
02204     {
02205       $this->privCloseFd();
02206       $this->privSwapBackMagicQuotes();
02207 
02208       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
02209 
02210       // ----- Return
02211       return PclZip::errorCode();
02212     }
02213 
02214     // ----- Copy the files from the archive to the temporary file
02215     // TBC : Here I should better append the file and go back to erase the central dir
02216     $v_size = $v_central_dir['offset'];
02217     while ($v_size != 0)
02218     {
02219       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
02220       $v_buffer = fread($this->zip_fd, $v_read_size);
02221       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
02222       $v_size -= $v_read_size;
02223     }
02224 
02225     // ----- Swap the file descriptor
02226     // Here is a trick : I swap the temporary fd with the zip fd, in order to use
02227     // the following methods on the temporary fil and not the real archive
02228     $v_swap = $this->zip_fd;
02229     $this->zip_fd = $v_zip_temp_fd;
02230     $v_zip_temp_fd = $v_swap;
02231 
02232     // ----- Add the files
02233     $v_header_list = array();
02234     if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
02235     {
02236       fclose($v_zip_temp_fd);
02237       $this->privCloseFd();
02238       @unlink($v_zip_temp_name);
02239       $this->privSwapBackMagicQuotes();
02240 
02241       // ----- Return
02242       return $v_result;
02243     }
02244 
02245     // ----- Store the offset of the central dir
02246     $v_offset = @ftell($this->zip_fd);
02247 
02248     // ----- Copy the block of file headers from the old archive
02249     $v_size = $v_central_dir['size'];
02250     while ($v_size != 0)
02251     {
02252       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
02253       $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
02254       @fwrite($this->zip_fd, $v_buffer, $v_read_size);
02255       $v_size -= $v_read_size;
02256     }
02257 
02258     // ----- Create the Central Dir files header
02259     for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
02260     {
02261       // ----- Create the file header
02262       if ($v_header_list[$i]['status'] == 'ok') {
02263         if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
02264           fclose($v_zip_temp_fd);
02265           $this->privCloseFd();
02266           @unlink($v_zip_temp_name);
02267           $this->privSwapBackMagicQuotes();
02268 
02269           // ----- Return
02270           return $v_result;
02271         }
02272         $v_count++;
02273       }
02274 
02275       // ----- Transform the header to a 'usable' info
02276       $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
02277     }
02278 
02279     // ----- Zip file comment
02280     $v_comment = $v_central_dir['comment'];
02281     if (isset($p_options[PCLZIP_OPT_COMMENT])) {
02282       $v_comment = $p_options[PCLZIP_OPT_COMMENT];
02283     }
02284     if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
02285       $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
02286     }
02287     if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
02288       $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
02289     }
02290 
02291     // ----- Calculate the size of the central header
02292     $v_size = @ftell($this->zip_fd)-$v_offset;
02293 
02294     // ----- Create the central dir footer
02295     if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
02296     {
02297       // ----- Reset the file list
02298       unset($v_header_list);
02299       $this->privSwapBackMagicQuotes();
02300 
02301       // ----- Return
02302       return $v_result;
02303     }
02304 
02305     // ----- Swap back the file descriptor
02306     $v_swap = $this->zip_fd;
02307     $this->zip_fd = $v_zip_temp_fd;
02308     $v_zip_temp_fd = $v_swap;
02309 
02310     // ----- Close
02311     $this->privCloseFd();
02312 
02313     // ----- Close the temporary file
02314     @fclose($v_zip_temp_fd);
02315 
02316     // ----- Magic quotes trick
02317     $this->privSwapBackMagicQuotes();
02318 
02319     // ----- Delete the zip file
02320     // TBC : I should test the result ...
02321     @unlink($this->zipname);
02322 
02323     // ----- Rename the temporary file
02324     // TBC : I should test the result ...
02325     //@rename($v_zip_temp_name, $this->zipname);
02326     PclZipUtilRename($v_zip_temp_name, $this->zipname);
02327 
02328     // ----- Return
02329     return $v_result;
02330   }

PclZip::privAddFile ( p_filedescr,
&$  p_header,
&$  p_options 
)

Definition at line 2525 of file pclzip.lib.php.

02526   {
02527     $v_result=1;
02528     
02529     // ----- Working variable
02530     $p_filename = $p_filedescr['filename'];
02531 
02532     // TBC : Already done in the fileAtt check ... ?
02533     if ($p_filename == "") {
02534       // ----- Error log
02535       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
02536 
02537       // ----- Return
02538       return PclZip::errorCode();
02539     }
02540   
02541     // ----- Look for a stored different filename 
02542     /* TBC : Removed
02543     if (isset($p_filedescr['stored_filename'])) {
02544       $v_stored_filename = $p_filedescr['stored_filename'];
02545     }
02546     else {
02547       $v_stored_filename = $p_filedescr['stored_filename'];
02548     }
02549     */
02550 
02551     // ----- Set the file properties
02552     clearstatcache();
02553     $p_header['version'] = 20;
02554     $p_header['version_extracted'] = 10;
02555     $p_header['flag'] = 0;
02556     $p_header['compression'] = 0;
02557     $p_header['crc'] = 0;
02558     $p_header['compressed_size'] = 0;
02559     $p_header['filename_len'] = strlen($p_filename);
02560     $p_header['extra_len'] = 0;
02561     $p_header['disk'] = 0;
02562     $p_header['internal'] = 0;
02563     $p_header['offset'] = 0;
02564     $p_header['filename'] = $p_filename;
02565 // TBC : Removed    $p_header['stored_filename'] = $v_stored_filename;
02566     $p_header['stored_filename'] = $p_filedescr['stored_filename'];
02567     $p_header['extra'] = '';
02568     $p_header['status'] = 'ok';
02569     $p_header['index'] = -1;
02570 
02571     // ----- Look for regular file
02572     if ($p_filedescr['type']=='file') {
02573       $p_header['external'] = 0x00000000;
02574       $p_header['size'] = filesize($p_filename);
02575     }
02576     
02577     // ----- Look for regular folder
02578     else if ($p_filedescr['type']=='folder') {
02579       $p_header['external'] = 0x00000010;
02580       $p_header['mtime'] = filemtime($p_filename);
02581       $p_header['size'] = filesize($p_filename);
02582     }
02583     
02584     // ----- Look for virtual file
02585     else if ($p_filedescr['type'] == 'virtual_file') {
02586       $p_header['external'] = 0x00000000;
02587       $p_header['size'] = strlen($p_filedescr['content']);
02588     }
02589     
02590 
02591     // ----- Look for filetime
02592     if (isset($p_filedescr['mtime'])) {
02593       $p_header['mtime'] = $p_filedescr['mtime'];
02594     }
02595     else if ($p_filedescr['type'] == 'virtual_file') {
02596       $p_header['mtime'] = time();
02597     }
02598     else {
02599       $p_header['mtime'] = filemtime($p_filename);
02600     }
02601 
02602     // ------ Look for file comment
02603     if (isset($p_filedescr['comment'])) {
02604       $p_header['comment_len'] = strlen($p_filedescr['comment']);
02605       $p_header['comment'] = $p_filedescr['comment'];
02606     }
02607     else {
02608       $p_header['comment_len'] = 0;
02609       $p_header['comment'] = '';
02610     }
02611 
02612     // ----- Look for pre-add callback
02613     if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
02614 
02615       // ----- Generate a local information
02616       $v_local_header = array();
02617       $this->privConvertHeader2FileInfo($p_header, $v_local_header);
02618 
02619       // ----- Call the callback
02620       // Here I do not use call_user_func() because I need to send a reference to the
02621       // header.
02622 //      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
02623       $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
02624       if ($v_result == 0) {
02625         // ----- Change the file status
02626         $p_header['status'] = "skipped";
02627         $v_result = 1;
02628       }
02629 
02630       // ----- Update the informations
02631       // Only some fields can be modified
02632       if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
02633         $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
02634       }
02635     }
02636 
02637     // ----- Look for empty stored filename
02638     if ($p_header['stored_filename'] == "") {
02639       $p_header['status'] = "filtered";
02640     }
02641     
02642     // ----- Check the path length
02643     if (strlen($p_header['stored_filename']) > 0xFF) {
02644       $p_header['status'] = 'filename_too_long';
02645     }
02646 
02647     // ----- Look if no error, or file not skipped
02648     if ($p_header['status'] == 'ok') {
02649 
02650       // ----- Look for a file
02651       if ($p_filedescr['type'] == 'file') {
02652         // ----- Look for using temporary file to zip
02653         if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) 
02654             && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
02655                 || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
02656                     && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
02657           $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
02658           if ($v_result < PCLZIP_ERR_NO_ERROR) {
02659             return $v_result;
02660           }
02661         }
02662         
02663         // ----- Use "in memory" zip algo
02664         else {
02665 
02666         // ----- Open the source file
02667         if (($v_file = @fopen($p_filename, "rb")) == 0) {
02668           PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
02669           return PclZip::errorCode();
02670         }
02671 
02672         // ----- Read the file content
02673         $v_content = @fread($v_file, $p_header['size']);
02674 
02675         // ----- Close the file
02676         @fclose($v_file);
02677 
02678         // ----- Calculate the CRC
02679         $p_header['crc'] = @crc32($v_content);
02680         
02681         // ----- Look for no compression
02682         if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
02683           // ----- Set header parameters
02684           $p_header['compressed_size'] = $p_header['size'];
02685           $p_header['compression'] = 0;
02686         }
02687         
02688         // ----- Look for normal compression
02689         else {
02690           // ----- Compress the content
02691           $v_content = @gzdeflate($v_content);
02692 
02693           // ----- Set header parameters
02694           $p_header['compressed_size'] = strlen($v_content);
02695           $p_header['compression'] = 8;
02696         }
02697         
02698         // ----- Call the header generation
02699         if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
02700           @fclose($v_file);
02701           return $v_result;
02702         }
02703 
02704         // ----- Write the compressed (or not) content
02705         @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
02706 
02707         }
02708 
02709       }
02710 
02711       // ----- Look for a virtual file (a file from string)
02712       else if ($p_filedescr['type'] == 'virtual_file') {
02713           
02714         $v_content = $p_filedescr['content'];
02715 
02716         // ----- Calculate the CRC
02717         $p_header['crc'] = @crc32($v_content);
02718         
02719         // ----- Look for no compression
02720         if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
02721           // ----- Set header parameters
02722           $p_header['compressed_size'] = $p_header['size'];
02723           $p_header['compression'] = 0;
02724         }
02725         
02726         // ----- Look for normal compression
02727         else {
02728           // ----- Compress the content
02729           $v_content = @gzdeflate($v_content);
02730 
02731           // ----- Set header parameters
02732           $p_header['compressed_size'] = strlen($v_content);
02733           $p_header['compression'] = 8;
02734         }
02735         
02736         // ----- Call the header generation
02737         if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
02738           @fclose($v_file);
02739           return $v_result;
02740         }
02741 
02742         // ----- Write the compressed (or not) content
02743         @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
02744       }
02745 
02746       // ----- Look for a directory
02747       else if ($p_filedescr['type'] == 'folder') {
02748         // ----- Look for directory last '/'
02749         if (@substr($p_header['stored_filename'], -1) != '/') {
02750           $p_header['stored_filename'] .= '/';
02751         }
02752 
02753         // ----- Set the file properties
02754         $p_header['size'] = 0;
02755         //$p_header['external'] = 0x41FF0010;   // Value for a folder : to be checked
02756         $p_header['external'] = 0x00000010;   // Value for a folder : to be checked
02757 
02758         // ----- Call the header generation
02759         if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
02760         {
02761           return $v_result;
02762         }
02763       }
02764     }
02765 
02766     // ----- Look for post-add callback
02767     if (isset($p_options[PCLZIP_CB_POST_ADD])) {
02768 
02769       // ----- Generate a local information
02770       $v_local_header = array();
02771       $this->privConvertHeader2FileInfo($p_header, $v_local_header);
02772 
02773       // ----- Call the callback
02774       // Here I do not use call_user_func() because I need to send a reference to the
02775       // header.
02776 //      eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
02777       $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
02778       if ($v_result == 0) {
02779         // ----- Ignored
02780         $v_result = 1;
02781       }
02782 
02783       // ----- Update the informations
02784       // Nothing can be modified
02785     }
02786 
02787     // ----- Return
02788     return $v_result;
02789   }

PclZip::privAddFileList ( p_filedescr_list,
&$  p_result_list,
&$  p_options 
)

Definition at line 2463 of file pclzip.lib.php.

02464   {
02465     $v_result=1;
02466     $v_header = array();
02467 
02468     // ----- Recuperate the current number of elt in list
02469     $v_nb = sizeof($p_result_list);
02470 
02471     // ----- Loop on the files
02472     for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {
02473       // ----- Format the filename
02474       $p_filedescr_list[$j]['filename']
02475       = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
02476       
02477 
02478       // ----- Skip empty file names
02479       // TBC : Can this be possible ? not checked in DescrParseAtt ?
02480       if ($p_filedescr_list[$j]['filename'] == "") {
02481         continue;
02482       }
02483 
02484       // ----- Check the filename
02485       if (   ($p_filedescr_list[$j]['type'] != 'virtual_file')
02486           && (!file_exists($p_filedescr_list[$j]['filename']))) {
02487         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
02488         return PclZip::errorCode();
02489       }
02490 
02491       // ----- Look if it is a file or a dir with no all path remove option
02492       // or a dir with all its path removed
02493 //      if (   (is_file($p_filedescr_list[$j]['filename']))
02494 //          || (   is_dir($p_filedescr_list[$j]['filename'])
02495       if (   ($p_filedescr_list[$j]['type'] == 'file')
02496           || ($p_filedescr_list[$j]['type'] == 'virtual_file')
02497           || (   ($p_filedescr_list[$j]['type'] == 'folder')
02498               && (   !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
02499                   || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))
02500           ) {
02501 
02502         // ----- Add the file
02503         $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,
02504                                        $p_options);
02505         if ($v_result != 1) {
02506           return $v_result;
02507         }
02508 
02509         // ----- Store the file infos
02510         $p_result_list[$v_nb++] = $v_header;
02511       }
02512     }
02513 
02514     // ----- Return
02515     return $v_result;
02516   }

PclZip::privAddFileUsingTempFile ( p_filedescr,
&$  p_header,
&$  p_options 
)

Definition at line 2798 of file pclzip.lib.php.

02799   {
02800     $v_result=PCLZIP_ERR_NO_ERROR;
02801     
02802     // ----- Working variable
02803     $p_filename = $p_filedescr['filename'];
02804 
02805 
02806     // ----- Open the source file
02807     if (($v_file = @fopen($p_filename, "rb")) == 0) {
02808       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
02809       return PclZip::errorCode();
02810     }
02811 
02812     // ----- Creates a compressed temporary file
02813     $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
02814     if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
02815       fclose($v_file);
02816       PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
02817       return PclZip::errorCode();
02818     }
02819 
02820     // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
02821     $v_size = filesize($p_filename);
02822     while ($v_size != 0) {
02823       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
02824       $v_buffer = @fread($v_file, $v_read_size);
02825       //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
02826       @gzputs($v_file_compressed, $v_buffer, $v_read_size);
02827       $v_size -= $v_read_size;
02828     }
02829 
02830     // ----- Close the file
02831     @fclose($v_file);
02832     @gzclose($v_file_compressed);
02833 
02834     // ----- Check the minimum file size
02835     if (filesize($v_gzip_temp_name) < 18) {
02836       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
02837       return PclZip::errorCode();
02838     }
02839 
02840     // ----- Extract the compressed attributes
02841     if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
02842       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
02843       return PclZip::errorCode();
02844     }
02845 
02846     // ----- Read the gzip file header
02847     $v_binary_data = @fread($v_file_compressed, 10);
02848     $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
02849 
02850     // ----- Check some parameters
02851     $v_data_header['os'] = bin2hex($v_data_header['os']);
02852 
02853     // ----- Read the gzip file footer
02854     @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
02855     $v_binary_data = @fread($v_file_compressed, 8);
02856     $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
02857 
02858     // ----- Set the attributes
02859     $p_header['compression'] = ord($v_data_header['cm']);
02860     //$p_header['mtime'] = $v_data_header['mtime'];
02861     $p_header['crc'] = $v_data_footer['crc'];
02862     $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
02863 
02864     // ----- Close the file
02865     @fclose($v_file_compressed);
02866 
02867     // ----- Call the header generation
02868     if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
02869       return $v_result;
02870     }
02871 
02872     // ----- Add the compressed data
02873     if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
02874     {
02875       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
02876       return PclZip::errorCode();
02877     }
02878 
02879     // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
02880     fseek($v_file_compressed, 10);
02881     $v_size = $p_header['compressed_size'];
02882     while ($v_size != 0)
02883     {
02884       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
02885       $v_buffer = @fread($v_file_compressed, $v_read_size);
02886       //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
02887       @fwrite($this->zip_fd, $v_buffer, $v_read_size);
02888       $v_size -= $v_read_size;
02889     }
02890 
02891     // ----- Close the file
02892     @fclose($v_file_compressed);
02893 
02894     // ----- Unlink the temporary file
02895     @unlink($v_gzip_temp_name);
02896     
02897     // ----- Return
02898     return $v_result;
02899   }

PclZip::privAddList ( p_filedescr_list,
&$  p_result_list,
&$  p_options 
)

Definition at line 2399 of file pclzip.lib.php.

02400   {
02401     $v_result=1;
02402 
02403     // ----- Add the files
02404     $v_header_list = array();
02405     if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
02406     {
02407       // ----- Return
02408       return $v_result;
02409     }
02410 
02411     // ----- Store the offset of the central dir
02412     $v_offset = @ftell($this->zip_fd);
02413 
02414     // ----- Create the Central Dir files header
02415     for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
02416     {
02417       // ----- Create the file header
02418       if ($v_header_list[$i]['status'] == 'ok') {
02419         if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
02420           // ----- Return
02421           return $v_result;
02422         }
02423         $v_count++;
02424       }
02425 
02426       // ----- Transform the header to a 'usable' info
02427       $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
02428     }
02429 
02430     // ----- Zip file comment
02431     $v_comment = '';
02432     if (isset($p_options[PCLZIP_OPT_COMMENT])) {
02433       $v_comment = $p_options[PCLZIP_OPT_COMMENT];
02434     }
02435 
02436     // ----- Calculate the size of the central header
02437     $v_size = @ftell($this->zip_fd)-$v_offset;
02438 
02439     // ----- Create the central dir footer
02440     if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
02441     {
02442       // ----- Reset the file list
02443       unset($v_header_list);
02444 
02445       // ----- Return
02446       return $v_result;
02447     }
02448 
02449     // ----- Return
02450     return $v_result;
02451   }

PclZip::privCalculateStoredFilename ( &$  p_filedescr,
&$  p_options 
)

Definition at line 2910 of file pclzip.lib.php.

02911   {
02912     $v_result=1;
02913     
02914     // ----- Working variables
02915     $p_filename = $p_filedescr['filename'];
02916     if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
02917       $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
02918     }
02919     else {
02920       $p_add_dir = '';
02921     }
02922     if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
02923       $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
02924     }
02925     else {
02926       $p_remove_dir = '';
02927     }
02928     if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
02929       $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
02930     }
02931     else {
02932       $p_remove_all_dir = 0;
02933     }
02934 
02935 
02936     // ----- Look for full name change
02937     if (isset($p_filedescr['new_full_name'])) {
02938       // ----- Remove drive letter if any
02939       $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
02940     }
02941     
02942     // ----- Look for path and/or short name change
02943     else {
02944 
02945       // ----- Look for short name change
02946       // Its when we cahnge just the filename but not the path
02947       if (isset($p_filedescr['new_short_name'])) {
02948         $v_path_info = pathinfo($p_filename);
02949         $v_dir = '';
02950         if ($v_path_info['dirname'] != '') {
02951           $v_dir = $v_path_info['dirname'].'/';
02952         }
02953         $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
02954       }
02955       else {
02956         // ----- Calculate the stored filename
02957         $v_stored_filename = $p_filename;
02958       }
02959 
02960       // ----- Look for all path to remove
02961       if ($p_remove_all_dir) {
02962         $v_stored_filename = basename($p_filename);
02963       }
02964       // ----- Look for partial path remove
02965       else if ($p_remove_dir != "") {
02966         if (substr($p_remove_dir, -1) != '/')
02967           $p_remove_dir .= "/";
02968 
02969         if (   (substr($p_filename, 0, 2) == "./")
02970             || (substr($p_remove_dir, 0, 2) == "./")) {
02971             
02972           if (   (substr($p_filename, 0, 2) == "./")
02973               && (substr($p_remove_dir, 0, 2) != "./")) {
02974             $p_remove_dir = "./".$p_remove_dir;
02975           }
02976           if (   (substr($p_filename, 0, 2) != "./")
02977               && (substr($p_remove_dir, 0, 2) == "./")) {
02978             $p_remove_dir = substr($p_remove_dir, 2);
02979           }
02980         }
02981 
02982         $v_compare = PclZipUtilPathInclusion($p_remove_dir,
02983                                              $v_stored_filename);
02984         if ($v_compare > 0) {
02985           if ($v_compare == 2) {
02986             $v_stored_filename = "";
02987           }
02988           else {
02989             $v_stored_filename = substr($v_stored_filename,
02990                                         strlen($p_remove_dir));
02991           }
02992         }
02993       }
02994       
02995       // ----- Remove drive letter if any
02996       $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
02997       
02998       // ----- Look for path to add
02999       if ($p_add_dir != "") {
03000         if (substr($p_add_dir, -1) == "/")
03001           $v_stored_filename = $p_add_dir.$v_stored_filename;
03002         else
03003           $v_stored_filename = $p_add_dir."/".$v_stored_filename;
03004       }
03005     }
03006 
03007     // ----- Filename (reduce the path of stored name)
03008     $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
03009     $p_filedescr['stored_filename'] = $v_stored_filename;
03010     
03011     // ----- Return
03012     return $v_result;
03013   }

PclZip::privCheckFileHeaders ( &$  p_local_header,
&$  p_central_header 
)

Definition at line 4488 of file pclzip.lib.php.

Referenced by privDeleteByRule().

04489   {
04490     $v_result=1;
04491 
04492         // ----- Check the static values
04493         // TBC
04494         if ($p_local_header['filename'] != $p_central_header['filename']) {
04495         }
04496         if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
04497         }
04498         if ($p_local_header['flag'] != $p_central_header['flag']) {
04499         }
04500         if ($p_local_header['compression'] != $p_central_header['compression']) {
04501         }
04502         if ($p_local_header['mtime'] != $p_central_header['mtime']) {
04503         }
04504         if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
04505         }
04506   
04507         // ----- Look for flag bit 3
04508         if (($p_local_header['flag'] & 8) == 8) {
04509           $p_local_header['size'] = $p_central_header['size'];
04510           $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
04511           $p_local_header['crc'] = $p_central_header['crc'];
04512         }
04513 
04514     // ----- Return
04515     return $v_result;
04516   }

PclZip::privCheckFormat ( p_level = 0  ) 

Definition at line 1373 of file pclzip.lib.php.

Referenced by delete(), extract(), extractByIndex(), listContent(), and properties().

01374   {
01375     $v_result = true;
01376 
01377         // ----- Reset the file system cache
01378     clearstatcache();
01379 
01380     // ----- Reset the error handler
01381     $this->privErrorReset();
01382 
01383     // ----- Look if the file exits
01384     if (!is_file($this->zipname)) {
01385       // ----- Error log
01386       PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
01387       return(false);
01388     }
01389 
01390     // ----- Check that the file is readeable
01391     if (!is_readable($this->zipname)) {
01392       // ----- Error log
01393       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
01394       return(false);
01395     }
01396 
01397     // ----- Check the magic code
01398     // TBC
01399 
01400     // ----- Check the central header
01401     // TBC
01402 
01403     // ----- Check each file header
01404     // TBC
01405 
01406     // ----- Return
01407     return $v_result;
01408   }

PclZip::privCloseFd (  ) 

Definition at line 2372 of file pclzip.lib.php.

Referenced by privDeleteByRule(), and privMerge().

02373   {
02374     $v_result=1;
02375 
02376     if ($this->zip_fd != 0)
02377       @fclose($this->zip_fd);
02378     $this->zip_fd = 0;
02379 
02380     // ----- Return
02381     return $v_result;
02382   }

PclZip::privConvertHeader2FileInfo ( p_header,
&$  p_info 
)

Definition at line 3236 of file pclzip.lib.php.

03237   {
03238     $v_result=1;
03239 
03240     // ----- Get the interesting attributes
03241     $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
03242     $p_info['filename'] = $v_temp_path;
03243     $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
03244     $p_info['stored_filename'] = $v_temp_path;
03245     $p_info['size'] = $p_header['size'];
03246     $p_info['compressed_size'] = $p_header['compressed_size'];
03247     $p_info['mtime'] = $p_header['mtime'];
03248     $p_info['comment'] = $p_header['comment'];
03249     $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
03250     $p_info['index'] = $p_header['index'];
03251     $p_info['status'] = $p_header['status'];
03252     $p_info['crc'] = $p_header['crc'];
03253 
03254     // ----- Return
03255     return $v_result;
03256   }

PclZip::privCreate ( p_filedescr_list,
&$  p_result_list,
&$  p_options 
)

Definition at line 2124 of file pclzip.lib.php.

Referenced by create().

02125   {
02126     $v_result=1;
02127     $v_list_detail = array();
02128     
02129     // ----- Magic quotes trick
02130     $this->privDisableMagicQuotes();
02131 
02132     // ----- Open the file in write mode
02133     if (($v_result = $this->privOpenFd('wb')) != 1)
02134     {
02135       // ----- Return
02136       return $v_result;
02137     }
02138 
02139     // ----- Add the list of files
02140     $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
02141 
02142     // ----- Close
02143     $this->privCloseFd();
02144 
02145     // ----- Magic quotes trick
02146     $this->privSwapBackMagicQuotes();
02147 
02148     // ----- Return
02149     return $v_result;
02150   }

PclZip::privDeleteByRule ( &$  p_result_list,
&$  p_options 
)

Definition at line 4682 of file pclzip.lib.php.

Referenced by delete().

04683   {
04684     $v_result=1;
04685     $v_list_detail = array();
04686 
04687     // ----- Open the zip file
04688     if (($v_result=$this->privOpenFd('rb')) != 1)
04689     {
04690       // ----- Return
04691       return $v_result;
04692     }
04693 
04694     // ----- Read the central directory informations
04695     $v_central_dir = array();
04696     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
04697     {
04698       $this->privCloseFd();
04699       return $v_result;
04700     }
04701 
04702     // ----- Go to beginning of File
04703     @rewind($this->zip_fd);
04704 
04705     // ----- Scan all the files
04706     // ----- Start at beginning of Central Dir
04707     $v_pos_entry = $v_central_dir['offset'];
04708     @rewind($this->zip_fd);
04709     if (@fseek($this->zip_fd, $v_pos_entry))
04710     {
04711       // ----- Close the zip file
04712       $this->privCloseFd();
04713 
04714       // ----- Error log
04715       PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
04716 
04717       // ----- Return
04718       return PclZip::errorCode();
04719     }
04720 
04721     // ----- Read each entry
04722     $v_header_list = array();
04723     $j_start = 0;
04724     for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
04725     {
04726 
04727       // ----- Read the file header
04728       $v_header_list[$v_nb_extracted] = array();
04729       if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
04730       {
04731         // ----- Close the zip file
04732         $this->privCloseFd();
04733 
04734         return $v_result;
04735       }
04736 
04737 
04738       // ----- Store the index
04739       $v_header_list[$v_nb_extracted]['index'] = $i;
04740 
04741       // ----- Look for the specific extract rules
04742       $v_found = false;
04743 
04744       // ----- Look for extract by name rule
04745       if (   (isset($p_options[PCLZIP_OPT_BY_NAME]))
04746           && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
04747 
04748           // ----- Look if the filename is in the list
04749           for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
04750 
04751               // ----- Look for a directory
04752               if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
04753 
04754                   // ----- Look if the directory is in the filename path
04755                   if (   (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
04756                       && (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])) {
04757                       $v_found = true;
04758                   }
04759                   elseif (   (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
04760                           && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
04761                       $v_found = true;
04762                   }
04763               }
04764               // ----- Look for a filename
04765               elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
04766                   $v_found = true;
04767               }
04768           }
04769       }
04770 
04771       // ----- Look for extract by ereg rule
04772       // ereg() is deprecated with PHP 5.3
04773       /*
04774       else if (   (isset($p_options[PCLZIP_OPT_BY_EREG]))
04775                && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
04776 
04777           if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
04778               $v_found = true;
04779           }
04780       }
04781       */
04782 
04783       // ----- Look for extract by preg rule
04784       else if (   (isset($p_options[PCLZIP_OPT_BY_PREG]))
04785                && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
04786 
04787           if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
04788               $v_found = true;
04789           }
04790       }
04791 
04792       // ----- Look for extract by index rule
04793       else if (   (isset($p_options[PCLZIP_OPT_BY_INDEX]))
04794                && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
04795 
04796           // ----- Look if the index is in the list
04797           for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
04798 
04799               if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
04800                   $v_found = true;
04801               }
04802               if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
04803                   $j_start = $j+1;
04804               }
04805 
04806               if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
04807                   break;
04808               }
04809           }
04810       }
04811       else {
04812         $v_found = true;
04813       }
04814 
04815       // ----- Look for deletion
04816       if ($v_found)
04817       {
04818         unset($v_header_list[$v_nb_extracted]);
04819       }
04820       else
04821       {
04822         $v_nb_extracted++;
04823       }
04824     }
04825 
04826     // ----- Look if something need to be deleted
04827     if ($v_nb_extracted > 0) {
04828 
04829         // ----- Creates a temporay file
04830         $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
04831 
04832         // ----- Creates a temporary zip archive
04833         $v_temp_zip = new PclZip($v_zip_temp_name);
04834 
04835         // ----- Open the temporary zip file in write mode
04836         if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
04837             $this->privCloseFd();
04838 
04839             // ----- Return
04840             return $v_result;
04841         }
04842 
04843         // ----- Look which file need to be kept
04844         for ($i=0; $i<sizeof($v_header_list); $i++) {
04845 
04846             // ----- Calculate the position of the header
04847             @rewind($this->zip_fd);
04848             if (@fseek($this->zip_fd,  $v_header_list[$i]['offset'])) {
04849                 // ----- Close the zip file
04850                 $this->privCloseFd();
04851                 $v_temp_zip->privCloseFd();
04852                 @unlink($v_zip_temp_name);
04853 
04854                 // ----- Error log
04855                 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
04856 
04857                 // ----- Return
04858                 return PclZip::errorCode();
04859             }
04860 
04861             // ----- Read the file header
04862             $v_local_header = array();
04863             if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
04864                 // ----- Close the zip file
04865                 $this->privCloseFd();
04866                 $v_temp_zip->privCloseFd();
04867                 @unlink($v_zip_temp_name);
04868 
04869                 // ----- Return
04870                 return $v_result;
04871             }
04872             
04873             // ----- Check that local file header is same as central file header
04874             if ($this->privCheckFileHeaders($v_local_header,
04875                                                         $v_header_list[$i]) != 1) {
04876                 // TBC
04877             }
04878             unset($v_local_header);
04879 
04880             // ----- Write the file header
04881             if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
04882                 // ----- Close the zip file
04883                 $this->privCloseFd();
04884                 $v_temp_zip->privCloseFd();
04885                 @unlink($v_zip_temp_name);
04886 
04887                 // ----- Return
04888                 return $v_result;
04889             }
04890 
04891             // ----- Read/write the data block
04892             if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
04893                 // ----- Close the zip file
04894                 $this->privCloseFd();
04895                 $v_temp_zip->privCloseFd();
04896                 @unlink($v_zip_temp_name);
04897 
04898                 // ----- Return
04899                 return $v_result;
04900             }
04901         }
04902 
04903         // ----- Store the offset of the central dir
04904         $v_offset = @ftell($v_temp_zip->zip_fd);
04905 
04906         // ----- Re-Create the Central Dir files header
04907         for ($i=0; $i<sizeof($v_header_list); $i++) {
04908             // ----- Create the file header
04909             if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
04910                 $v_temp_zip->privCloseFd();
04911                 $this->privCloseFd();
04912                 @unlink($v_zip_temp_name);
04913 
04914                 // ----- Return
04915                 return $v_result;
04916             }
04917 
04918             // ----- Transform the header to a 'usable' info
04919             $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
04920         }
04921 
04922 
04923         // ----- Zip file comment
04924         $v_comment = '';
04925         if (isset($p_options[PCLZIP_OPT_COMMENT])) {
04926           $v_comment = $p_options[PCLZIP_OPT_COMMENT];
04927         }
04928 
04929         // ----- Calculate the size of the central header
04930         $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
04931 
04932         // ----- Create the central dir footer
04933         if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
04934             // ----- Reset the file list
04935             unset($v_header_list);
04936             $v_temp_zip->privCloseFd();
04937             $this->privCloseFd();
04938             @unlink($v_zip_temp_name);
04939 
04940             // ----- Return
04941             return $v_result;
04942         }
04943 
04944         // ----- Close
04945         $v_temp_zip->privCloseFd();
04946         $this->privCloseFd();
04947 
04948         // ----- Delete the zip file
04949         // TBC : I should test the result ...
04950         @unlink($this->zipname);
04951 
04952         // ----- Rename the temporary file
04953         // TBC : I should test the result ...
04954         //@rename($v_zip_temp_name, $this->zipname);
04955         PclZipUtilRename($v_zip_temp_name, $this->zipname);
04956     
04957         // ----- Destroy the temporary archive
04958         unset($v_temp_zip);
04959     }
04960     
04961     // ----- Remove every files : reset the file
04962     else if ($v_central_dir['entries'] != 0) {
04963         $this->privCloseFd();
04964 
04965         if (($v_result = $this->privOpenFd('wb')) != 1) {
04966           return $v_result;
04967         }
04968 
04969         if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
04970           return $v_result;
04971         }
04972 
04973         $this->privCloseFd();
04974     }
04975 
04976     // ----- Return
04977     return $v_result;
04978   }

PclZip::privDirCheck ( p_dir,
p_is_dir = false 
)

Definition at line 4992 of file pclzip.lib.php.

04993   {
04994     $v_result = 1;
04995 
04996 
04997     // ----- Remove the final '/'
04998     if (($p_is_dir) && (substr($p_dir, -1)=='/'))
04999     {
05000       $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
05001     }
05002 
05003     // ----- Check the directory availability
05004     if ((is_dir($p_dir)) || ($p_dir == ""))
05005     {
05006       return 1;
05007     }
05008 
05009     // ----- Extract parent directory
05010     $p_parent_dir = dirname($p_dir);
05011 
05012     // ----- Just a check
05013     if ($p_parent_dir != $p_dir)
05014     {
05015       // ----- Look for parent directory
05016       if ($p_parent_dir != "")
05017       {
05018         if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
05019         {
05020           return $v_result;
05021         }
05022       }
05023     }
05024 
05025     // ----- Create the directory
05026     if (!@mkdir($p_dir, 0777))
05027     {
05028       // ----- Error log
05029       PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
05030 
05031       // ----- Return
05032       return PclZip::errorCode();
05033     }
05034 
05035     // ----- Return
05036     return $v_result;
05037   }

PclZip::privDisableMagicQuotes (  ) 

Definition at line 5327 of file pclzip.lib.php.

Referenced by delete(), and properties().

05328   {
05329     $v_result=1;
05330 
05331     // ----- Look if function exists
05332     if (   (!function_exists("get_magic_quotes_runtime"))
05333             || (!function_exists("set_magic_quotes_runtime"))) {
05334       return $v_result;
05335         }
05336 
05337     // ----- Look if already done
05338     if ($this->magic_quotes_status != -1) {
05339       return $v_result;
05340         }
05341 
05342         // ----- Get and memorize the magic_quote value
05343         $this->magic_quotes_status = @get_magic_quotes_runtime();
05344 
05345         // ----- Disable magic_quotes
05346         if ($this->magic_quotes_status == 1) {
05347           @set_magic_quotes_runtime(0);
05348         }
05349 
05350     // ----- Return
05351     return $v_result;
05352   }

PclZip::privDuplicate ( p_archive_filename  ) 

Definition at line 5232 of file pclzip.lib.php.

Referenced by privMerge().

05233   {
05234     $v_result=1;
05235 
05236     // ----- Look if the $p_archive_filename exists
05237     if (!is_file($p_archive_filename))
05238     {
05239 
05240       // ----- Nothing to duplicate, so duplicate is a success.
05241       $v_result = 1;
05242 
05243       // ----- Return
05244       return $v_result;
05245     }
05246 
05247     // ----- Open the zip file
05248     if (($v_result=$this->privOpenFd('wb')) != 1)
05249     {
05250       // ----- Return
05251       return $v_result;
05252     }
05253 
05254     // ----- Open the temporary file in write mode
05255     if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
05256     {
05257       $this->privCloseFd();
05258 
05259       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
05260 
05261       // ----- Return
05262       return PclZip::errorCode();
05263     }
05264 
05265     // ----- Copy the files from the archive to the temporary file
05266     // TBC : Here I should better append the file and go back to erase the central dir
05267     $v_size = filesize($p_archive_filename);
05268     while ($v_size != 0)
05269     {
05270       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
05271       $v_buffer = fread($v_zip_temp_fd, $v_read_size);
05272       @fwrite($this->zip_fd, $v_buffer, $v_read_size);
05273       $v_size -= $v_read_size;
05274     }
05275 
05276     // ----- Close
05277     $this->privCloseFd();
05278 
05279     // ----- Close the temporary file
05280     @fclose($v_zip_temp_fd);
05281 
05282     // ----- Return
05283     return $v_result;
05284   }

PclZip::privErrorLog ( p_error_code = 0,
p_error_string = '' 
)

Definition at line 5292 of file pclzip.lib.php.

Referenced by add(), create(), extract(), extractByIndex(), privDeleteByRule(), privDirCheck(), privMerge(), and properties().

05293   {
05294     if (PCLZIP_ERROR_EXTERNAL == 1) {
05295       PclError($p_error_code, $p_error_string);
05296     }
05297     else {
05298       $this->error_code = $p_error_code;
05299       $this->error_string = $p_error_string;
05300     }
05301   }

PclZip::privErrorReset (  ) 

Definition at line 5309 of file pclzip.lib.php.

Referenced by add(), create(), delete(), extract(), extractByIndex(), listContent(), and properties().

05310   {
05311     if (PCLZIP_ERROR_EXTERNAL == 1) {
05312       PclErrorReset();
05313     }
05314     else {
05315       $this->error_code = 0;
05316       $this->error_string = '';
05317     }
05318   }

PclZip::privExtractByRule ( &$  p_file_list,
p_path,
p_remove_path,
p_remove_all_path,
&$  p_options 
)

Definition at line 3275 of file pclzip.lib.php.

Referenced by extract(), and extractByIndex().

03276   {
03277     $v_result=1;
03278 
03279     // ----- Magic quotes trick
03280     $this->privDisableMagicQuotes();
03281 
03282     // ----- Check the path
03283     if (   ($p_path == "")
03284             || (   (substr($p_path, 0, 1) != "/")
03285                     && (substr($p_path, 0, 3) != "../")
03286                         && (substr($p_path,1,2)!=":/")))
03287       $p_path = "./".$p_path;
03288 
03289     // ----- Reduce the path last (and duplicated) '/'
03290     if (($p_path != "./") && ($p_path != "/"))
03291     {
03292       // ----- Look for the path end '/'
03293       while (substr($p_path, -1) == "/")
03294       {
03295         $p_path = substr($p_path, 0, strlen($p_path)-1);
03296       }
03297     }
03298 
03299     // ----- Look for path to remove format (should end by /)
03300     if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
03301     {
03302       $p_remove_path .= '/';
03303     }
03304     $p_remove_path_size = strlen($p_remove_path);
03305 
03306     // ----- Open the zip file
03307     if (($v_result = $this->privOpenFd('rb')) != 1)
03308     {
03309       $this->privSwapBackMagicQuotes();
03310       return $v_result;
03311     }
03312 
03313     // ----- Read the central directory informations
03314     $v_central_dir = array();
03315     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
03316     {
03317       // ----- Close the zip file
03318       $this->privCloseFd();
03319       $this->privSwapBackMagicQuotes();
03320 
03321       return $v_result;
03322     }
03323 
03324     // ----- Start at beginning of Central Dir
03325     $v_pos_entry = $v_central_dir['offset'];
03326 
03327     // ----- Read each entry
03328     $j_start = 0;
03329     for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
03330     {
03331 
03332       // ----- Read next Central dir entry
03333       @rewind($this->zip_fd);
03334       if (@fseek($this->zip_fd, $v_pos_entry))
03335       {
03336         // ----- Close the zip file
03337         $this->privCloseFd();
03338         $this->privSwapBackMagicQuotes();
03339 
03340         // ----- Error log
03341         PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
03342 
03343         // ----- Return
03344         return PclZip::errorCode();
03345       }
03346 
03347       // ----- Read the file header
03348       $v_header = array();
03349       if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
03350       {
03351         // ----- Close the zip file
03352         $this->privCloseFd();
03353         $this->privSwapBackMagicQuotes();
03354 
03355         return $v_result;
03356       }
03357 
03358       // ----- Store the index
03359       $v_header['index'] = $i;
03360 
03361       // ----- Store the file position
03362       $v_pos_entry = ftell($this->zip_fd);
03363 
03364       // ----- Look for the specific extract rules
03365       $v_extract = false;
03366 
03367       // ----- Look for extract by name rule
03368       if (   (isset($p_options[PCLZIP_OPT_BY_NAME]))
03369           && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
03370 
03371           // ----- Look if the filename is in the list
03372           for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
03373 
03374               // ----- Look for a directory
03375               if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
03376 
03377                   // ----- Look if the directory is in the filename path
03378                   if (   (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
03379                       && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
03380                       $v_extract = true;
03381                   }
03382               }
03383               // ----- Look for a filename
03384               elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
03385                   $v_extract = true;
03386               }
03387           }
03388       }
03389 
03390       // ----- Look for extract by ereg rule
03391       // ereg() is deprecated with PHP 5.3
03392       /* 
03393       else if (   (isset($p_options[PCLZIP_OPT_BY_EREG]))
03394                && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
03395 
03396           if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
03397               $v_extract = true;
03398           }
03399       }
03400       */
03401 
03402       // ----- Look for extract by preg rule
03403       else if (   (isset($p_options[PCLZIP_OPT_BY_PREG]))
03404                && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
03405 
03406           if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
03407               $v_extract = true;
03408           }
03409       }
03410 
03411       // ----- Look for extract by index rule
03412       else if (   (isset($p_options[PCLZIP_OPT_BY_INDEX]))
03413                && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
03414           
03415           // ----- Look if the index is in the list
03416           for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
03417 
03418               if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
03419                   $v_extract = true;
03420               }
03421               if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
03422                   $j_start = $j+1;
03423               }
03424 
03425               if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
03426                   break;
03427               }
03428           }
03429       }
03430 
03431       // ----- Look for no rule, which means extract all the archive
03432       else {
03433           $v_extract = true;
03434       }
03435 
03436           // ----- Check compression method
03437           if (   ($v_extract)
03438               && (   ($v_header['compression'] != 8)
03439                       && ($v_header['compression'] != 0))) {
03440           $v_header['status'] = 'unsupported_compression';
03441 
03442           // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
03443           if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
03444                       && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
03445 
03446               $this->privSwapBackMagicQuotes();
03447               
03448               PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
03449                                                "Filename '".$v_header['stored_filename']."' is "
03450                                                            ."compressed by an unsupported compression "
03451                                                            ."method (".$v_header['compression'].") ");
03452 
03453               return PclZip::errorCode();
03454                   }
03455           }
03456           
03457           // ----- Check encrypted files
03458           if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
03459           $v_header['status'] = 'unsupported_encryption';
03460 
03461           // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
03462           if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
03463                       && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
03464 
03465               $this->privSwapBackMagicQuotes();
03466 
03467               PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
03468                                                "Unsupported encryption for "
03469                                                            ." filename '".$v_header['stored_filename']
03470                                                                    ."'");
03471 
03472               return PclZip::errorCode();
03473                   }
03474     }
03475 
03476       // ----- Look for real extraction
03477       if (($v_extract) && ($v_header['status'] != 'ok')) {
03478           $v_result = $this->privConvertHeader2FileInfo($v_header,
03479                                                         $p_file_list[$v_nb_extracted++]);
03480           if ($v_result != 1) {
03481               $this->privCloseFd();
03482               $this->privSwapBackMagicQuotes();
03483               return $v_result;
03484           }
03485 
03486           $v_extract = false;
03487       }
03488       
03489       // ----- Look for real extraction
03490       if ($v_extract)
03491       {
03492 
03493         // ----- Go to the file position
03494         @rewind($this->zip_fd);
03495         if (@fseek($this->zip_fd, $v_header['offset']))
03496         {
03497           // ----- Close the zip file
03498           $this->privCloseFd();
03499 
03500           $this->privSwapBackMagicQuotes();
03501 
03502           // ----- Error log
03503           PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
03504 
03505           // ----- Return
03506           return PclZip::errorCode();
03507         }
03508 
03509         // ----- Look for extraction as string
03510         if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
03511 
03512           $v_string = '';
03513 
03514           // ----- Extracting the file
03515           $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
03516           if ($v_result1 < 1) {
03517             $this->privCloseFd();
03518             $this->privSwapBackMagicQuotes();
03519             return $v_result1;
03520           }
03521 
03522           // ----- Get the only interesting attributes
03523           if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
03524           {
03525             // ----- Close the zip file
03526             $this->privCloseFd();
03527             $this->privSwapBackMagicQuotes();
03528 
03529             return $v_result;
03530           }
03531 
03532           // ----- Set the file content
03533           $p_file_list[$v_nb_extracted]['content'] = $v_string;
03534 
03535           // ----- Next extracted file
03536           $v_nb_extracted++;
03537           
03538           // ----- Look for user callback abort
03539           if ($v_result1 == 2) {
03540                 break;
03541           }
03542         }
03543         // ----- Look for extraction in standard output
03544         elseif (   (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
03545                         && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
03546           // ----- Extracting the file in standard output
03547           $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
03548           if ($v_result1 < 1) {
03549             $this->privCloseFd();
03550             $this->privSwapBackMagicQuotes();
03551             return $v_result1;
03552           }
03553 
03554           // ----- Get the only interesting attributes
03555           if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
03556             $this->privCloseFd();
03557             $this->privSwapBackMagicQuotes();
03558             return $v_result;
03559           }
03560 
03561           // ----- Look for user callback abort
03562           if ($v_result1 == 2) {
03563                 break;
03564           }
03565         }
03566         // ----- Look for normal extraction
03567         else {
03568           // ----- Extracting the file
03569           $v_result1 = $this->privExtractFile($v_header,
03570                                                       $p_path, $p_remove_path,
03571                                                                                           $p_remove_all_path,
03572                                                                                           $p_options);
03573           if ($v_result1 < 1) {
03574             $this->privCloseFd();
03575             $this->privSwapBackMagicQuotes();
03576             return $v_result1;
03577           }
03578 
03579           // ----- Get the only interesting attributes
03580           if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
03581           {
03582             // ----- Close the zip file
03583             $this->privCloseFd();
03584             $this->privSwapBackMagicQuotes();
03585 
03586             return $v_result;
03587           }
03588 
03589           // ----- Look for user callback abort
03590           if ($v_result1 == 2) {
03591                 break;
03592           }
03593         }
03594       }
03595     }
03596 
03597     // ----- Close the zip file
03598     $this->privCloseFd();
03599     $this->privSwapBackMagicQuotes();
03600 
03601     // ----- Return
03602     return $v_result;
03603   }

PclZip::privExtractFile ( &$  p_entry,
p_path,
p_remove_path,
p_remove_all_path,
&$  p_options 
)

Definition at line 3615 of file pclzip.lib.php.

03616   {
03617     $v_result=1;
03618 
03619     // ----- Read the file header
03620     if (($v_result = $this->privReadFileHeader($v_header)) != 1)
03621     {
03622       // ----- Return
03623       return $v_result;
03624     }
03625 
03626 
03627     // ----- Check that the file header is coherent with $p_entry info
03628     if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
03629         // TBC
03630     }
03631 
03632     // ----- Look for all path to remove
03633     if ($p_remove_all_path == true) {
03634         // ----- Look for folder entry that not need to be extracted
03635         if (($p_entry['external']&0x00000010)==0x00000010) {
03636 
03637             $p_entry['status'] = "filtered";
03638 
03639             return $v_result;
03640         }
03641 
03642         // ----- Get the basename of the path
03643         $p_entry['filename'] = basename($p_entry['filename']);
03644     }
03645 
03646     // ----- Look for path to remove
03647     else if ($p_remove_path != "")
03648     {
03649       if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
03650       {
03651 
03652         // ----- Change the file status
03653         $p_entry['status'] = "filtered";
03654 
03655         // ----- Return
03656         return $v_result;
03657       }
03658 
03659       $p_remove_path_size = strlen($p_remove_path);
03660       if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
03661       {
03662 
03663         // ----- Remove the path
03664         $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
03665 
03666       }
03667     }
03668 
03669     // ----- Add the path
03670     if ($p_path != '') {
03671       $p_entry['filename'] = $p_path."/".$p_entry['filename'];
03672     }
03673     
03674     // ----- Check a base_dir_restriction
03675     if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
03676       $v_inclusion
03677       = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
03678                                 $p_entry['filename']); 
03679       if ($v_inclusion == 0) {
03680 
03681         PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
03682                                              "Filename '".$p_entry['filename']."' is "
03683                                                                  ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
03684 
03685         return PclZip::errorCode();
03686       }
03687     }
03688 
03689     // ----- Look for pre-extract callback
03690     if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
03691 
03692       // ----- Generate a local information
03693       $v_local_header = array();
03694       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
03695 
03696       // ----- Call the callback
03697       // Here I do not use call_user_func() because I need to send a reference to the
03698       // header.
03699 //      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
03700       $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
03701       if ($v_result == 0) {
03702         // ----- Change the file status
03703         $p_entry['status'] = "skipped";
03704         $v_result = 1;
03705       }
03706       
03707       // ----- Look for abort result
03708       if ($v_result == 2) {
03709         // ----- This status is internal and will be changed in 'skipped'
03710         $p_entry['status'] = "aborted";
03711         $v_result = PCLZIP_ERR_USER_ABORTED;
03712       }
03713 
03714       // ----- Update the informations
03715       // Only some fields can be modified
03716       $p_entry['filename'] = $v_local_header['filename'];
03717     }
03718 
03719 
03720     // ----- Look if extraction should be done
03721     if ($p_entry['status'] == 'ok') {
03722 
03723     // ----- Look for specific actions while the file exist
03724     if (file_exists($p_entry['filename']))
03725     {
03726 
03727       // ----- Look if file is a directory
03728       if (is_dir($p_entry['filename']))
03729       {
03730 
03731         // ----- Change the file status
03732         $p_entry['status'] = "already_a_directory";
03733         
03734         // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
03735         // For historical reason first PclZip implementation does not stop
03736         // when this kind of error occurs.
03737         if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
03738                     && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
03739 
03740             PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
03741                                              "Filename '".$p_entry['filename']."' is "
03742                                                                  ."already used by an existing directory");
03743 
03744             return PclZip::errorCode();
03745                     }
03746       }
03747       // ----- Look if file is write protected
03748       else if (!is_writeable($p_entry['filename']))
03749       {
03750 
03751         // ----- Change the file status
03752         $p_entry['status'] = "write_protected";
03753 
03754         // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
03755         // For historical reason first PclZip implementation does not stop
03756         // when this kind of error occurs.
03757         if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
03758                     && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
03759 
03760             PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
03761                                              "Filename '".$p_entry['filename']."' exists "
03762                                                                  ."and is write protected");
03763 
03764             return PclZip::errorCode();
03765                     }
03766       }
03767 
03768       // ----- Look if the extracted file is older
03769       else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
03770       {
03771         // ----- Change the file status
03772         if (   (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
03773                     && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
03774                   }
03775                     else {
03776             $p_entry['status'] = "newer_exist";
03777 
03778             // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
03779             // For historical reason first PclZip implementation does not stop
03780             // when this kind of error occurs.
03781             if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
03782                         && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
03783 
03784                 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
03785                                      "Newer version of '".$p_entry['filename']."' exists "
03786                                             ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
03787 
03788                 return PclZip::errorCode();
03789                       }
03790                     }
03791       }
03792       else {
03793       }
03794     }
03795 
03796     // ----- Check the directory availability and create it if necessary
03797     else {
03798       if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
03799         $v_dir_to_check = $p_entry['filename'];
03800       else if (!strstr($p_entry['filename'], "/"))
03801         $v_dir_to_check = "";
03802       else
03803         $v_dir_to_check = dirname($p_entry['filename']);
03804 
03805         if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
03806   
03807           // ----- Change the file status
03808           $p_entry['status'] = "path_creation_fail";
03809   
03810           // ----- Return
03811           //return $v_result;
03812           $v_result = 1;
03813         }
03814       }
03815     }
03816 
03817     // ----- Look if extraction should be done
03818     if ($p_entry['status'] == 'ok') {
03819 
03820       // ----- Do the extraction (if not a folder)
03821       if (!(($p_entry['external']&0x00000010)==0x00000010))
03822       {
03823         // ----- Look for not compressed file
03824         if ($p_entry['compression'] == 0) {
03825 
03826                   // ----- Opening destination file
03827           if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
03828           {
03829 
03830             // ----- Change the file status
03831             $p_entry['status'] = "write_error";
03832 
03833             // ----- Return
03834             return $v_result;
03835           }
03836 
03837 
03838           // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
03839           $v_size = $p_entry['compressed_size'];
03840           while ($v_size != 0)
03841           {
03842             $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
03843             $v_buffer = @fread($this->zip_fd, $v_read_size);
03844             /* Try to speed up the code
03845             $v_binary_data = pack('a'.$v_read_size, $v_buffer);
03846             @fwrite($v_dest_file, $v_binary_data, $v_read_size);
03847             */
03848             @fwrite($v_dest_file, $v_buffer, $v_read_size);            
03849             $v_size -= $v_read_size;
03850           }
03851 
03852           // ----- Closing the destination file
03853           fclose($v_dest_file);
03854 
03855           // ----- Change the file mtime
03856           touch($p_entry['filename'], $p_entry['mtime']);
03857           
03858 
03859         }
03860         else {
03861           // ----- TBC
03862           // Need to be finished
03863           if (($p_entry['flag'] & 1) == 1) {
03864             PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
03865             return PclZip::errorCode();
03866           }
03867 
03868 
03869           // ----- Look for using temporary file to unzip
03870           if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) 
03871               && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
03872                   || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
03873                       && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
03874             $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
03875             if ($v_result < PCLZIP_ERR_NO_ERROR) {
03876               return $v_result;
03877             }
03878           }
03879           
03880           // ----- Look for extract in memory
03881           else {
03882 
03883           
03884             // ----- Read the compressed file in a buffer (one shot)
03885             $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
03886             
03887             // ----- Decompress the file
03888             $v_file_content = @gzinflate($v_buffer);
03889             unset($v_buffer);
03890             if ($v_file_content === FALSE) {
03891   
03892               // ----- Change the file status
03893               // TBC
03894               $p_entry['status'] = "error";
03895               
03896               return $v_result;
03897             }
03898             
03899             // ----- Opening destination file
03900             if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
03901   
03902               // ----- Change the file status
03903               $p_entry['status'] = "write_error";
03904   
03905               return $v_result;
03906             }
03907   
03908             // ----- Write the uncompressed data
03909             @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
03910             unset($v_file_content);
03911   
03912             // ----- Closing the destination file
03913             @fclose($v_dest_file);
03914             
03915           }
03916 
03917           // ----- Change the file mtime
03918           @touch($p_entry['filename'], $p_entry['mtime']);
03919         }
03920 
03921         // ----- Look for chmod option
03922         if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
03923 
03924           // ----- Change the mode of the file
03925           @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
03926         }
03927 
03928       }
03929     }
03930 
03931         // ----- Change abort status
03932         if ($p_entry['status'] == "aborted") {
03933         $p_entry['status'] = "skipped";
03934         }
03935         
03936     // ----- Look for post-extract callback
03937     elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
03938 
03939       // ----- Generate a local information
03940       $v_local_header = array();
03941       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
03942 
03943       // ----- Call the callback
03944       // Here I do not use call_user_func() because I need to send a reference to the
03945       // header.
03946 //      eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
03947       $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
03948 
03949       // ----- Look for abort result
03950       if ($v_result == 2) {
03951         $v_result = PCLZIP_ERR_USER_ABORTED;
03952       }
03953     }
03954 
03955     // ----- Return
03956     return $v_result;
03957   }

PclZip::privExtractFileAsString ( &$  p_entry,
&$  p_string,
&$  p_options 
)

Definition at line 4154 of file pclzip.lib.php.

04155   {
04156     $v_result=1;
04157 
04158     // ----- Read the file header
04159     $v_header = array();
04160     if (($v_result = $this->privReadFileHeader($v_header)) != 1)
04161     {
04162       // ----- Return
04163       return $v_result;
04164     }
04165 
04166 
04167     // ----- Check that the file header is coherent with $p_entry info
04168     if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
04169         // TBC
04170     }
04171 
04172     // ----- Look for pre-extract callback
04173     if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
04174 
04175       // ----- Generate a local information
04176       $v_local_header = array();
04177       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
04178 
04179       // ----- Call the callback
04180       // Here I do not use call_user_func() because I need to send a reference to the
04181       // header.
04182 //      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
04183       $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
04184       if ($v_result == 0) {
04185         // ----- Change the file status
04186         $p_entry['status'] = "skipped";
04187         $v_result = 1;
04188       }
04189       
04190       // ----- Look for abort result
04191       if ($v_result == 2) {
04192         // ----- This status is internal and will be changed in 'skipped'
04193         $p_entry['status'] = "aborted";
04194         $v_result = PCLZIP_ERR_USER_ABORTED;
04195       }
04196 
04197       // ----- Update the informations
04198       // Only some fields can be modified
04199       $p_entry['filename'] = $v_local_header['filename'];
04200     }
04201 
04202 
04203     // ----- Look if extraction should be done
04204     if ($p_entry['status'] == 'ok') {
04205 
04206       // ----- Do the extraction (if not a folder)
04207       if (!(($p_entry['external']&0x00000010)==0x00000010)) {
04208         // ----- Look for not compressed file
04209   //      if ($p_entry['compressed_size'] == $p_entry['size'])
04210         if ($p_entry['compression'] == 0) {
04211   
04212           // ----- Reading the file
04213           $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
04214         }
04215         else {
04216   
04217           // ----- Reading the file
04218           $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
04219           
04220           // ----- Decompress the file
04221           if (($p_string = @gzinflate($v_data)) === FALSE) {
04222               // TBC
04223           }
04224         }
04225   
04226         // ----- Trace
04227       }
04228       else {
04229           // TBC : error : can not extract a folder in a string
04230       }
04231       
04232     }
04233 
04234         // ----- Change abort status
04235         if ($p_entry['status'] == "aborted") {
04236         $p_entry['status'] = "skipped";
04237         }
04238         
04239     // ----- Look for post-extract callback
04240     elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
04241 
04242       // ----- Generate a local information
04243       $v_local_header = array();
04244       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
04245       
04246       // ----- Swap the content to header
04247       $v_local_header['content'] = $p_string;
04248       $p_string = '';
04249 
04250       // ----- Call the callback
04251       // Here I do not use call_user_func() because I need to send a reference to the
04252       // header.
04253 //      eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
04254       $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
04255 
04256       // ----- Swap back the content to header
04257       $p_string = $v_local_header['content'];
04258       unset($v_local_header['content']);
04259 
04260       // ----- Look for abort result
04261       if ($v_result == 2) {
04262         $v_result = PCLZIP_ERR_USER_ABORTED;
04263       }
04264     }
04265 
04266     // ----- Return
04267     return $v_result;
04268   }

PclZip::privExtractFileInOutput ( &$  p_entry,
&$  p_options 
)

Definition at line 4042 of file pclzip.lib.php.

04043   {
04044     $v_result=1;
04045 
04046     // ----- Read the file header
04047     if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
04048       return $v_result;
04049     }
04050 
04051 
04052     // ----- Check that the file header is coherent with $p_entry info
04053     if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
04054         // TBC
04055     }
04056 
04057     // ----- Look for pre-extract callback
04058     if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
04059 
04060       // ----- Generate a local information
04061       $v_local_header = array();
04062       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
04063 
04064       // ----- Call the callback
04065       // Here I do not use call_user_func() because I need to send a reference to the
04066       // header.
04067 //      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
04068       $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
04069       if ($v_result == 0) {
04070         // ----- Change the file status
04071         $p_entry['status'] = "skipped";
04072         $v_result = 1;
04073       }
04074 
04075       // ----- Look for abort result
04076       if ($v_result == 2) {
04077         // ----- This status is internal and will be changed in 'skipped'
04078         $p_entry['status'] = "aborted";
04079         $v_result = PCLZIP_ERR_USER_ABORTED;
04080       }
04081 
04082       // ----- Update the informations
04083       // Only some fields can be modified
04084       $p_entry['filename'] = $v_local_header['filename'];
04085     }
04086 
04087     // ----- Trace
04088 
04089     // ----- Look if extraction should be done
04090     if ($p_entry['status'] == 'ok') {
04091 
04092       // ----- Do the extraction (if not a folder)
04093       if (!(($p_entry['external']&0x00000010)==0x00000010)) {
04094         // ----- Look for not compressed file
04095         if ($p_entry['compressed_size'] == $p_entry['size']) {
04096 
04097           // ----- Read the file in a buffer (one shot)
04098           $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
04099 
04100           // ----- Send the file to the output
04101           echo $v_buffer;
04102           unset($v_buffer);
04103         }
04104         else {
04105 
04106           // ----- Read the compressed file in a buffer (one shot)
04107           $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
04108           
04109           // ----- Decompress the file
04110           $v_file_content = gzinflate($v_buffer);
04111           unset($v_buffer);
04112 
04113           // ----- Send the file to the output
04114           echo $v_file_content;
04115           unset($v_file_content);
04116         }
04117       }
04118     }
04119 
04120         // ----- Change abort status
04121         if ($p_entry['status'] == "aborted") {
04122       $p_entry['status'] = "skipped";
04123         }
04124 
04125     // ----- Look for post-extract callback
04126     elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
04127 
04128       // ----- Generate a local information
04129       $v_local_header = array();
04130       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
04131 
04132       // ----- Call the callback
04133       // Here I do not use call_user_func() because I need to send a reference to the
04134       // header.
04135 //      eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
04136       $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
04137 
04138       // ----- Look for abort result
04139       if ($v_result == 2) {
04140         $v_result = PCLZIP_ERR_USER_ABORTED;
04141       }
04142     }
04143 
04144     return $v_result;
04145   }

PclZip::privExtractFileUsingTempFile ( &$  p_entry,
&$  p_options 
)

Definition at line 3966 of file pclzip.lib.php.

03967   {
03968     $v_result=1;
03969         
03970     // ----- Creates a temporary file
03971     $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
03972     if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
03973       fclose($v_file);
03974       PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
03975       return PclZip::errorCode();
03976     }
03977 
03978 
03979     // ----- Write gz file format header
03980     $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
03981     @fwrite($v_dest_file, $v_binary_data, 10);
03982 
03983     // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
03984     $v_size = $p_entry['compressed_size'];
03985     while ($v_size != 0)
03986     {
03987       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
03988       $v_buffer = @fread($this->zip_fd, $v_read_size);
03989       //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
03990       @fwrite($v_dest_file, $v_buffer, $v_read_size);
03991       $v_size -= $v_read_size;
03992     }
03993 
03994     // ----- Write gz file format footer
03995     $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
03996     @fwrite($v_dest_file, $v_binary_data, 8);
03997 
03998     // ----- Close the temporary file
03999     @fclose($v_dest_file);
04000 
04001     // ----- Opening destination file
04002     if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
04003       $p_entry['status'] = "write_error";
04004       return $v_result;
04005     }
04006 
04007     // ----- Open the temporary gz file
04008     if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
04009       @fclose($v_dest_file);
04010       $p_entry['status'] = "read_error";
04011       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
04012       return PclZip::errorCode();
04013     }
04014 
04015 
04016     // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
04017     $v_size = $p_entry['size'];
04018     while ($v_size != 0) {
04019       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
04020       $v_buffer = @gzread($v_src_file, $v_read_size);
04021       //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
04022       @fwrite($v_dest_file, $v_buffer, $v_read_size);
04023       $v_size -= $v_read_size;
04024     }
04025     @fclose($v_dest_file);
04026     @gzclose($v_src_file);
04027 
04028     // ----- Delete the temporary file
04029     @unlink($v_gzip_temp_name);
04030     
04031     // ----- Return
04032     return $v_result;
04033   }

PclZip::privFileDescrExpand ( &$  p_filedescr_list,
&$  p_options 
)

Definition at line 1999 of file pclzip.lib.php.

Referenced by add(), and create().

02000   {
02001     $v_result=1;
02002     
02003     // ----- Create a result list
02004     $v_result_list = array();
02005     
02006     // ----- Look each entry
02007     for ($i=0; $i<sizeof($p_filedescr_list); $i++) {
02008       
02009       // ----- Get filedescr
02010       $v_descr = $p_filedescr_list[$i];
02011       
02012       // ----- Reduce the filename
02013       $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
02014       $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
02015       
02016       // ----- Look for real file or folder
02017       if (file_exists($v_descr['filename'])) {
02018         if (@is_file($v_descr['filename'])) {
02019           $v_descr['type'] = 'file';
02020         }
02021         else if (@is_dir($v_descr['filename'])) {
02022           $v_descr['type'] = 'folder';
02023         }
02024         else if (@is_link($v_descr['filename'])) {
02025           // skip
02026           continue;
02027         }
02028         else {
02029           // skip
02030           continue;
02031         }
02032       }
02033       
02034       // ----- Look for string added as file
02035       else if (isset($v_descr['content'])) {
02036         $v_descr['type'] = 'virtual_file';
02037       }
02038       
02039       // ----- Missing file
02040       else {
02041         // ----- Error log
02042         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist");
02043 
02044         // ----- Return
02045         return PclZip::errorCode();
02046       }
02047       
02048       // ----- Calculate the stored filename
02049       $this->privCalculateStoredFilename($v_descr, $p_options);
02050       
02051       // ----- Add the descriptor in result list
02052       $v_result_list[sizeof($v_result_list)] = $v_descr;
02053       
02054       // ----- Look for folder
02055       if ($v_descr['type'] == 'folder') {
02056         // ----- List of items in folder
02057         $v_dirlist_descr = array();
02058         $v_dirlist_nb = 0;
02059         if ($v_folder_handler = @opendir($v_descr['filename'])) {
02060           while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
02061 
02062             // ----- Skip '.' and '..'
02063             if (($v_item_handler == '.') || ($v_item_handler == '..')) {
02064                 continue;
02065             }
02066             
02067             // ----- Compose the full filename
02068             $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
02069             
02070             // ----- Look for different stored filename
02071             // Because the name of the folder was changed, the name of the
02072             // files/sub-folders also change
02073             if (($v_descr['stored_filename'] != $v_descr['filename'])
02074                  && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
02075               if ($v_descr['stored_filename'] != '') {
02076                 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
02077               }
02078               else {
02079                 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
02080               }
02081             }
02082       
02083             $v_dirlist_nb++;
02084           }
02085           
02086           @closedir($v_folder_handler);
02087         }
02088         else {
02089           // TBC : unable to open folder in read mode
02090         }
02091         
02092         // ----- Expand each element of the list
02093         if ($v_dirlist_nb != 0) {
02094           // ----- Expand
02095           if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
02096             return $v_result;
02097           }
02098           
02099           // ----- Concat the resulting list
02100           $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
02101         }
02102         else {
02103         }
02104           
02105         // ----- Free local array
02106         unset($v_dirlist_descr);
02107       }
02108     }
02109     
02110     // ----- Get the result list
02111     $p_filedescr_list = $v_result_list;
02112 
02113     // ----- Return
02114     return $v_result;
02115   }

PclZip::privFileDescrParseAtt ( &$  p_file_list,
&$  p_filedescr,
v_options,
v_requested_options = false 
)

Definition at line 1870 of file pclzip.lib.php.

Referenced by add(), and create().

01871   {
01872     $v_result=1;
01873     
01874     // ----- For each file in the list check the attributes
01875     foreach ($p_file_list as $v_key => $v_value) {
01876     
01877       // ----- Check if the option is supported
01878       if (!isset($v_requested_options[$v_key])) {
01879         // ----- Error log
01880         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
01881 
01882         // ----- Return
01883         return PclZip::errorCode();
01884       }
01885 
01886       // ----- Look for attribute
01887       switch ($v_key) {
01888         case PCLZIP_ATT_FILE_NAME :
01889           if (!is_string($v_value)) {
01890             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
01891             return PclZip::errorCode();
01892           }
01893 
01894           $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
01895           
01896           if ($p_filedescr['filename'] == '') {
01897             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
01898             return PclZip::errorCode();
01899           }
01900 
01901         break;
01902 
01903         case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
01904           if (!is_string($v_value)) {
01905             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
01906             return PclZip::errorCode();
01907           }
01908 
01909           $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
01910 
01911           if ($p_filedescr['new_short_name'] == '') {
01912             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
01913             return PclZip::errorCode();
01914           }
01915         break;
01916 
01917         case PCLZIP_ATT_FILE_NEW_FULL_NAME :
01918           if (!is_string($v_value)) {
01919             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
01920             return PclZip::errorCode();
01921           }
01922 
01923           $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
01924 
01925           if ($p_filedescr['new_full_name'] == '') {
01926             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
01927             return PclZip::errorCode();
01928           }
01929         break;
01930 
01931         // ----- Look for options that takes a string
01932         case PCLZIP_ATT_FILE_COMMENT :
01933           if (!is_string($v_value)) {
01934             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
01935             return PclZip::errorCode();
01936           }
01937 
01938           $p_filedescr['comment'] = $v_value;
01939         break;
01940 
01941         case PCLZIP_ATT_FILE_MTIME :
01942           if (!is_integer($v_value)) {
01943             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
01944             return PclZip::errorCode();
01945           }
01946 
01947           $p_filedescr['mtime'] = $v_value;
01948         break;
01949 
01950         case PCLZIP_ATT_FILE_CONTENT :
01951           $p_filedescr['content'] = $v_value;
01952         break;
01953 
01954         default :
01955           // ----- Error log
01956           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
01957                                            "Unknown parameter '".$v_key."'");
01958 
01959           // ----- Return
01960           return PclZip::errorCode();
01961       }
01962 
01963       // ----- Look for mandatory options
01964       if ($v_requested_options !== false) {
01965         for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
01966           // ----- Look for mandatory option
01967           if ($v_requested_options[$key] == 'mandatory') {
01968             // ----- Look if present
01969             if (!isset($p_file_list[$key])) {
01970               PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
01971               return PclZip::errorCode();
01972             }
01973           }
01974         }
01975       }
01976     
01977     // end foreach
01978     }
01979     
01980     // ----- Return
01981     return $v_result;
01982   }

PclZip::privList ( &$  p_list  ) 

Definition at line 3149 of file pclzip.lib.php.

Referenced by listContent().

03150   {
03151     $v_result=1;
03152 
03153     // ----- Magic quotes trick
03154     $this->privDisableMagicQuotes();
03155 
03156     // ----- Open the zip file
03157     if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
03158     {
03159       // ----- Magic quotes trick
03160       $this->privSwapBackMagicQuotes();
03161       
03162       // ----- Error log
03163       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
03164 
03165       // ----- Return
03166       return PclZip::errorCode();
03167     }
03168 
03169     // ----- Read the central directory informations
03170     $v_central_dir = array();
03171     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
03172     {
03173       $this->privSwapBackMagicQuotes();
03174       return $v_result;
03175     }
03176 
03177     // ----- Go to beginning of Central Dir
03178     @rewind($this->zip_fd);
03179     if (@fseek($this->zip_fd, $v_central_dir['offset']))
03180     {
03181       $this->privSwapBackMagicQuotes();
03182 
03183       // ----- Error log
03184       PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
03185 
03186       // ----- Return
03187       return PclZip::errorCode();
03188     }
03189 
03190     // ----- Read each entry
03191     for ($i=0; $i<$v_central_dir['entries']; $i++)
03192     {
03193       // ----- Read the file header
03194       if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
03195       {
03196         $this->privSwapBackMagicQuotes();
03197         return $v_result;
03198       }
03199       $v_header['index'] = $i;
03200 
03201       // ----- Get the only interesting attributes
03202       $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
03203       unset($v_header);
03204     }
03205 
03206     // ----- Close the zip file
03207     $this->privCloseFd();
03208 
03209     // ----- Magic quotes trick
03210     $this->privSwapBackMagicQuotes();
03211 
03212     // ----- Return
03213     return $v_result;
03214   }

PclZip::privMerge ( &$  p_archive_to_add  ) 

Definition at line 5047 of file pclzip.lib.php.

05048   {
05049     $v_result=1;
05050 
05051     // ----- Look if the archive_to_add exists
05052     if (!is_file($p_archive_to_add->zipname))
05053     {
05054 
05055       // ----- Nothing to merge, so merge is a success
05056       $v_result = 1;
05057 
05058       // ----- Return
05059       return $v_result;
05060     }
05061 
05062     // ----- Look if the archive exists
05063     if (!is_file($this->zipname))
05064     {
05065 
05066       // ----- Do a duplicate
05067       $v_result = $this->privDuplicate($p_archive_to_add->zipname);
05068 
05069       // ----- Return
05070       return $v_result;
05071     }
05072 
05073     // ----- Open the zip file
05074     if (($v_result=$this->privOpenFd('rb')) != 1)
05075     {
05076       // ----- Return
05077       return $v_result;
05078     }
05079 
05080     // ----- Read the central directory informations
05081     $v_central_dir = array();
05082     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
05083     {
05084       $this->privCloseFd();
05085       return $v_result;
05086     }
05087 
05088     // ----- Go to beginning of File
05089     @rewind($this->zip_fd);
05090 
05091     // ----- Open the archive_to_add file
05092     if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
05093     {
05094       $this->privCloseFd();
05095 
05096       // ----- Return
05097       return $v_result;
05098     }
05099 
05100     // ----- Read the central directory informations
05101     $v_central_dir_to_add = array();
05102     if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
05103     {
05104       $this->privCloseFd();
05105       $p_archive_to_add->privCloseFd();
05106 
05107       return $v_result;
05108     }
05109 
05110     // ----- Go to beginning of File
05111     @rewind($p_archive_to_add->zip_fd);
05112 
05113     // ----- Creates a temporay file
05114     $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
05115 
05116     // ----- Open the temporary file in write mode
05117     if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
05118     {
05119       $this->privCloseFd();
05120       $p_archive_to_add->privCloseFd();
05121 
05122       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
05123 
05124       // ----- Return
05125       return PclZip::errorCode();
05126     }
05127 
05128     // ----- Copy the files from the archive to the temporary file
05129     // TBC : Here I should better append the file and go back to erase the central dir
05130     $v_size = $v_central_dir['offset'];
05131     while ($v_size != 0)
05132     {
05133       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
05134       $v_buffer = fread($this->zip_fd, $v_read_size);
05135       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
05136       $v_size -= $v_read_size;
05137     }
05138 
05139     // ----- Copy the files from the archive_to_add into the temporary file
05140     $v_size = $v_central_dir_to_add['offset'];
05141     while ($v_size != 0)
05142     {
05143       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
05144       $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
05145       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
05146       $v_size -= $v_read_size;
05147     }
05148 
05149     // ----- Store the offset of the central dir
05150     $v_offset = @ftell($v_zip_temp_fd);
05151 
05152     // ----- Copy the block of file headers from the old archive
05153     $v_size = $v_central_dir['size'];
05154     while ($v_size != 0)
05155     {
05156       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
05157       $v_buffer = @fread($this->zip_fd, $v_read_size);
05158       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
05159       $v_size -= $v_read_size;
05160     }
05161 
05162     // ----- Copy the block of file headers from the archive_to_add
05163     $v_size = $v_central_dir_to_add['size'];
05164     while ($v_size != 0)
05165     {
05166       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
05167       $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
05168       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
05169       $v_size -= $v_read_size;
05170     }
05171 
05172     // ----- Merge the file comments
05173     $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
05174 
05175     // ----- Calculate the size of the (new) central header
05176     $v_size = @ftell($v_zip_temp_fd)-$v_offset;
05177 
05178     // ----- Swap the file descriptor
05179     // Here is a trick : I swap the temporary fd with the zip fd, in order to use
05180     // the following methods on the temporary fil and not the real archive fd
05181     $v_swap = $this->zip_fd;
05182     $this->zip_fd = $v_zip_temp_fd;
05183     $v_zip_temp_fd = $v_swap;
05184 
05185     // ----- Create the central dir footer
05186     if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
05187     {
05188       $this->privCloseFd();
05189       $p_archive_to_add->privCloseFd();
05190       @fclose($v_zip_temp_fd);
05191       $this->zip_fd = null;
05192 
05193       // ----- Reset the file list
05194       unset($v_header_list);
05195 
05196       // ----- Return
05197       return $v_result;
05198     }
05199 
05200     // ----- Swap back the file descriptor
05201     $v_swap = $this->zip_fd;
05202     $this->zip_fd = $v_zip_temp_fd;
05203     $v_zip_temp_fd = $v_swap;
05204 
05205     // ----- Close
05206     $this->privCloseFd();
05207     $p_archive_to_add->privCloseFd();
05208 
05209     // ----- Close the temporary file
05210     @fclose($v_zip_temp_fd);
05211 
05212     // ----- Delete the zip file
05213     // TBC : I should test the result ...
05214     @unlink($this->zipname);
05215 
05216     // ----- Rename the temporary file
05217     // TBC : I should test the result ...
05218     //@rename($v_zip_temp_name, $this->zipname);
05219     PclZipUtilRename($v_zip_temp_name, $this->zipname);
05220 
05221     // ----- Return
05222     return $v_result;
05223   }

PclZip::privOpenFd ( p_mode  ) 

Definition at line 2338 of file pclzip.lib.php.

Referenced by privDeleteByRule(), and privMerge().

02339   {
02340     $v_result=1;
02341 
02342     // ----- Look if already open
02343     if ($this->zip_fd != 0)
02344     {
02345       // ----- Error log
02346       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
02347 
02348       // ----- Return
02349       return PclZip::errorCode();
02350     }
02351 
02352     // ----- Open the zip file
02353     if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
02354     {
02355       // ----- Error log
02356       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
02357 
02358       // ----- Return
02359       return PclZip::errorCode();
02360     }
02361 
02362     // ----- Return
02363     return $v_result;
02364   }

PclZip::privOptionDefaultThreshold ( &$  p_options  ) 

Definition at line 1826 of file pclzip.lib.php.

Referenced by add(), create(), extract(), and extractByIndex().

01827   {
01828     $v_result=1;
01829     
01830     if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
01831         || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
01832       return $v_result;
01833     }
01834     
01835     // ----- Get 'memory_limit' configuration value
01836     $v_memory_limit = ini_get('memory_limit');
01837     $v_memory_limit = trim($v_memory_limit);
01838     $last = strtolower(substr($v_memory_limit, -1));
01839  
01840     if($last == 'g')
01841         //$v_memory_limit = $v_memory_limit*1024*1024*1024;
01842         $v_memory_limit = $v_memory_limit*1073741824;
01843     if($last == 'm')
01844         //$v_memory_limit = $v_memory_limit*1024*1024;
01845         $v_memory_limit = $v_memory_limit*1048576;
01846     if($last == 'k')
01847         $v_memory_limit = $v_memory_limit*1024;
01848             
01849     $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
01850     
01851 
01852     // ----- Sanity check : No threshold if value lower than 1M
01853     if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
01854       unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
01855     }
01856           
01857     // ----- Return
01858     return $v_result;
01859   }

PclZip::privParseOptions ( &$  p_options_list,
p_size,
&$  v_result_list,
v_requested_options = false 
)

Definition at line 1426 of file pclzip.lib.php.

Referenced by add(), create(), delete(), extract(), and extractByIndex().

01427   {
01428     $v_result=1;
01429     
01430     // ----- Read the options
01431     $i=0;
01432     while ($i<$p_size) {
01433 
01434       // ----- Check if the option is supported
01435       if (!isset($v_requested_options[$p_options_list[$i]])) {
01436         // ----- Error log
01437         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
01438 
01439         // ----- Return
01440         return PclZip::errorCode();
01441       }
01442 
01443       // ----- Look for next option
01444       switch ($p_options_list[$i]) {
01445         // ----- Look for options that request a path value
01446         case PCLZIP_OPT_PATH :
01447         case PCLZIP_OPT_REMOVE_PATH :
01448         case PCLZIP_OPT_ADD_PATH :
01449           // ----- Check the number of parameters
01450           if (($i+1) >= $p_size) {
01451             // ----- Error log
01452             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01453 
01454             // ----- Return
01455             return PclZip::errorCode();
01456           }
01457 
01458           // ----- Get the value
01459           $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
01460           $i++;
01461         break;
01462 
01463         case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
01464           // ----- Check the number of parameters
01465           if (($i+1) >= $p_size) {
01466             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01467             return PclZip::errorCode();
01468           }
01469           
01470           // ----- Check for incompatible options
01471           if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
01472             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
01473             return PclZip::errorCode();
01474           }
01475           
01476           // ----- Check the value
01477           $v_value = $p_options_list[$i+1];
01478           if ((!is_integer($v_value)) || ($v_value<0)) {
01479             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01480             return PclZip::errorCode();
01481           }
01482 
01483           // ----- Get the value (and convert it in bytes)
01484           $v_result_list[$p_options_list[$i]] = $v_value*1048576;
01485           $i++;
01486         break;
01487 
01488         case PCLZIP_OPT_TEMP_FILE_ON :
01489           // ----- Check for incompatible options
01490           if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
01491             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
01492             return PclZip::errorCode();
01493           }
01494           
01495           $v_result_list[$p_options_list[$i]] = true;
01496         break;
01497 
01498         case PCLZIP_OPT_TEMP_FILE_OFF :
01499           // ----- Check for incompatible options
01500           if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
01501             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
01502             return PclZip::errorCode();
01503           }
01504           // ----- Check for incompatible options
01505           if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
01506             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
01507             return PclZip::errorCode();
01508           }
01509           
01510           $v_result_list[$p_options_list[$i]] = true;
01511         break;
01512 
01513         case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
01514           // ----- Check the number of parameters
01515           if (($i+1) >= $p_size) {
01516             // ----- Error log
01517             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01518 
01519             // ----- Return
01520             return PclZip::errorCode();
01521           }
01522 
01523           // ----- Get the value
01524           if (   is_string($p_options_list[$i+1])
01525               && ($p_options_list[$i+1] != '')) {
01526             $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
01527             $i++;
01528           }
01529           else {
01530           }
01531         break;
01532 
01533         // ----- Look for options that request an array of string for value
01534         case PCLZIP_OPT_BY_NAME :
01535           // ----- Check the number of parameters
01536           if (($i+1) >= $p_size) {
01537             // ----- Error log
01538             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01539 
01540             // ----- Return
01541             return PclZip::errorCode();
01542           }
01543 
01544           // ----- Get the value
01545           if (is_string($p_options_list[$i+1])) {
01546               $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
01547           }
01548           else if (is_array($p_options_list[$i+1])) {
01549               $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
01550           }
01551           else {
01552             // ----- Error log
01553             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01554 
01555             // ----- Return
01556             return PclZip::errorCode();
01557           }
01558           $i++;
01559         break;
01560 
01561         // ----- Look for options that request an EREG or PREG expression
01562         case PCLZIP_OPT_BY_EREG :
01563           // ereg() is deprecated starting with PHP 5.3. Move PCLZIP_OPT_BY_EREG
01564           // to PCLZIP_OPT_BY_PREG
01565           $p_options_list[$i] = PCLZIP_OPT_BY_PREG;
01566         case PCLZIP_OPT_BY_PREG :
01567         //case PCLZIP_OPT_CRYPT :
01568           // ----- Check the number of parameters
01569           if (($i+1) >= $p_size) {
01570             // ----- Error log
01571             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01572 
01573             // ----- Return
01574             return PclZip::errorCode();
01575           }
01576 
01577           // ----- Get the value
01578           if (is_string($p_options_list[$i+1])) {
01579               $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
01580           }
01581           else {
01582             // ----- Error log
01583             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01584 
01585             // ----- Return
01586             return PclZip::errorCode();
01587           }
01588           $i++;
01589         break;
01590 
01591         // ----- Look for options that takes a string
01592         case PCLZIP_OPT_COMMENT :
01593         case PCLZIP_OPT_ADD_COMMENT :
01594         case PCLZIP_OPT_PREPEND_COMMENT :
01595           // ----- Check the number of parameters
01596           if (($i+1) >= $p_size) {
01597             // ----- Error log
01598             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
01599                                              "Missing parameter value for option '"
01600                                                                  .PclZipUtilOptionText($p_options_list[$i])
01601                                                                  ."'");
01602 
01603             // ----- Return
01604             return PclZip::errorCode();
01605           }
01606 
01607           // ----- Get the value
01608           if (is_string($p_options_list[$i+1])) {
01609               $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
01610           }
01611           else {
01612             // ----- Error log
01613             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
01614                                              "Wrong parameter value for option '"
01615                                                                  .PclZipUtilOptionText($p_options_list[$i])
01616                                                                  ."'");
01617 
01618             // ----- Return
01619             return PclZip::errorCode();
01620           }
01621           $i++;
01622         break;
01623 
01624         // ----- Look for options that request an array of index
01625         case PCLZIP_OPT_BY_INDEX :
01626           // ----- Check the number of parameters
01627           if (($i+1) >= $p_size) {
01628             // ----- Error log
01629             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01630 
01631             // ----- Return
01632             return PclZip::errorCode();
01633           }
01634 
01635           // ----- Get the value
01636           $v_work_list = array();
01637           if (is_string($p_options_list[$i+1])) {
01638 
01639               // ----- Remove spaces
01640               $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
01641 
01642               // ----- Parse items
01643               $v_work_list = explode(",", $p_options_list[$i+1]);
01644           }
01645           else if (is_integer($p_options_list[$i+1])) {
01646               $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
01647           }
01648           else if (is_array($p_options_list[$i+1])) {
01649               $v_work_list = $p_options_list[$i+1];
01650           }
01651           else {
01652             // ----- Error log
01653             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01654 
01655             // ----- Return
01656             return PclZip::errorCode();
01657           }
01658           
01659           // ----- Reduce the index list
01660           // each index item in the list must be a couple with a start and
01661           // an end value : [0,3], [5-5], [8-10], ...
01662           // ----- Check the format of each item
01663           $v_sort_flag=false;
01664           $v_sort_value=0;
01665           for ($j=0; $j<sizeof($v_work_list); $j++) {
01666               // ----- Explode the item
01667               $v_item_list = explode("-", $v_work_list[$j]);
01668               $v_size_item_list = sizeof($v_item_list);
01669               
01670               // ----- TBC : Here we might check that each item is a
01671               // real integer ...
01672               
01673               // ----- Look for single value
01674               if ($v_size_item_list == 1) {
01675                   // ----- Set the option value
01676                   $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
01677                   $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
01678               }
01679               elseif ($v_size_item_list == 2) {
01680                   // ----- Set the option value
01681                   $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
01682                   $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
01683               }
01684               else {
01685                   // ----- Error log
01686                   PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01687 
01688                   // ----- Return
01689                   return PclZip::errorCode();
01690               }
01691 
01692 
01693               // ----- Look for list sort
01694               if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
01695                   $v_sort_flag=true;
01696 
01697                   // ----- TBC : An automatic sort should be writen ...
01698                   // ----- Error log
01699                   PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01700 
01701                   // ----- Return
01702                   return PclZip::errorCode();
01703               }
01704               $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
01705           }
01706           
01707           // ----- Sort the items
01708           if ($v_sort_flag) {
01709               // TBC : To Be Completed
01710           }
01711 
01712           // ----- Next option
01713           $i++;
01714         break;
01715 
01716         // ----- Look for options that request no value
01717         case PCLZIP_OPT_REMOVE_ALL_PATH :
01718         case PCLZIP_OPT_EXTRACT_AS_STRING :
01719         case PCLZIP_OPT_NO_COMPRESSION :
01720         case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
01721         case PCLZIP_OPT_REPLACE_NEWER :
01722         case PCLZIP_OPT_STOP_ON_ERROR :
01723           $v_result_list[$p_options_list[$i]] = true;
01724         break;
01725 
01726         // ----- Look for options that request an octal value
01727         case PCLZIP_OPT_SET_CHMOD :
01728           // ----- Check the number of parameters
01729           if (($i+1) >= $p_size) {
01730             // ----- Error log
01731             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01732 
01733             // ----- Return
01734             return PclZip::errorCode();
01735           }
01736 
01737           // ----- Get the value
01738           $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
01739           $i++;
01740         break;
01741 
01742         // ----- Look for options that request a call-back
01743         case PCLZIP_CB_PRE_EXTRACT :
01744         case PCLZIP_CB_POST_EXTRACT :
01745         case PCLZIP_CB_PRE_ADD :
01746         case PCLZIP_CB_POST_ADD :
01747         /* for futur use
01748         case PCLZIP_CB_PRE_DELETE :
01749         case PCLZIP_CB_POST_DELETE :
01750         case PCLZIP_CB_PRE_LIST :
01751         case PCLZIP_CB_POST_LIST :
01752         */
01753           // ----- Check the number of parameters
01754           if (($i+1) >= $p_size) {
01755             // ----- Error log
01756             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01757 
01758             // ----- Return
01759             return PclZip::errorCode();
01760           }
01761 
01762           // ----- Get the value
01763           $v_function_name = $p_options_list[$i+1];
01764 
01765           // ----- Check that the value is a valid existing function
01766           if (!function_exists($v_function_name)) {
01767             // ----- Error log
01768             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
01769 
01770             // ----- Return
01771             return PclZip::errorCode();
01772           }
01773 
01774           // ----- Set the attribute
01775           $v_result_list[$p_options_list[$i]] = $v_function_name;
01776           $i++;
01777         break;
01778 
01779         default :
01780           // ----- Error log
01781           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
01782                                        "Unknown parameter '"
01783                                                            .$p_options_list[$i]."'");
01784 
01785           // ----- Return
01786           return PclZip::errorCode();
01787       }
01788 
01789       // ----- Next options
01790       $i++;
01791     }
01792 
01793     // ----- Look for mandatory options
01794     if ($v_requested_options !== false) {
01795       for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
01796         // ----- Look for mandatory option
01797         if ($v_requested_options[$key] == 'mandatory') {
01798           // ----- Look if present
01799           if (!isset($v_result_list[$key])) {
01800             // ----- Error log
01801             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
01802 
01803             // ----- Return
01804             return PclZip::errorCode();
01805           }
01806         }
01807       }
01808     }
01809     
01810     // ----- Look for default values
01811     if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
01812       
01813     }
01814 
01815     // ----- Return
01816     return $v_result;
01817   }

PclZip::privReadCentralFileHeader ( &$  p_header  ) 

Definition at line 4380 of file pclzip.lib.php.

Referenced by privDeleteByRule().

04381   {
04382     $v_result=1;
04383 
04384     // ----- Read the 4 bytes signature
04385     $v_binary_data = @fread($this->zip_fd, 4);
04386     $v_data = unpack('Vid', $v_binary_data);
04387 
04388     // ----- Check signature
04389     if ($v_data['id'] != 0x02014b50)
04390     {
04391 
04392       // ----- Error log
04393       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
04394 
04395       // ----- Return
04396       return PclZip::errorCode();
04397     }
04398 
04399     // ----- Read the first 42 bytes of the header
04400     $v_binary_data = fread($this->zip_fd, 42);
04401 
04402     // ----- Look for invalid block size
04403     if (strlen($v_binary_data) != 42)
04404     {
04405       $p_header['filename'] = "";
04406       $p_header['status'] = "invalid_header";
04407 
04408       // ----- Error log
04409       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
04410 
04411       // ----- Return
04412       return PclZip::errorCode();
04413     }
04414 
04415     // ----- Extract the values
04416     $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);
04417 
04418     // ----- Get filename
04419     if ($p_header['filename_len'] != 0)
04420       $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
04421     else
04422       $p_header['filename'] = '';
04423 
04424     // ----- Get extra
04425     if ($p_header['extra_len'] != 0)
04426       $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
04427     else
04428       $p_header['extra'] = '';
04429 
04430     // ----- Get comment
04431     if ($p_header['comment_len'] != 0)
04432       $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
04433     else
04434       $p_header['comment'] = '';
04435 
04436     // ----- Extract properties
04437 
04438     // ----- Recuperate date in UNIX format
04439     //if ($p_header['mdate'] && $p_header['mtime'])
04440     // TBC : bug : this was ignoring time with 0/0/0
04441     if (1)
04442     {
04443       // ----- Extract time
04444       $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
04445       $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
04446       $v_seconde = ($p_header['mtime'] & 0x001F)*2;
04447 
04448       // ----- Extract date
04449       $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
04450       $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
04451       $v_day = $p_header['mdate'] & 0x001F;
04452 
04453       // ----- Get UNIX date format
04454       $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
04455 
04456     }
04457     else
04458     {
04459       $p_header['mtime'] = time();
04460     }
04461 
04462     // ----- Set the stored filename
04463     $p_header['stored_filename'] = $p_header['filename'];
04464 
04465     // ----- Set default status to ok
04466     $p_header['status'] = 'ok';
04467 
04468     // ----- Look if it is a directory
04469     if (substr($p_header['filename'], -1) == '/') {
04470       //$p_header['external'] = 0x41FF0010;
04471       $p_header['external'] = 0x00000010;
04472     }
04473 
04474 
04475     // ----- Return
04476     return $v_result;
04477   }

PclZip::privReadEndCentralDir ( &$  p_central_dir  ) 

Definition at line 4525 of file pclzip.lib.php.

Referenced by privDeleteByRule(), and privMerge().

04526   {
04527     $v_result=1;
04528 
04529     // ----- Go to the end of the zip file
04530     $v_size = filesize($this->zipname);
04531     @fseek($this->zip_fd, $v_size);
04532     if (@ftell($this->zip_fd) != $v_size)
04533     {
04534       // ----- Error log
04535       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
04536 
04537       // ----- Return
04538       return PclZip::errorCode();
04539     }
04540 
04541     // ----- First try : look if this is an archive with no commentaries (most of the time)
04542     // in this case the end of central dir is at 22 bytes of the file end
04543     $v_found = 0;
04544     if ($v_size > 26) {
04545       @fseek($this->zip_fd, $v_size-22);
04546       if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
04547       {
04548         // ----- Error log
04549         PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
04550 
04551         // ----- Return
04552         return PclZip::errorCode();
04553       }
04554 
04555       // ----- Read for bytes
04556       $v_binary_data = @fread($this->zip_fd, 4);
04557       $v_data = @unpack('Vid', $v_binary_data);
04558 
04559       // ----- Check signature
04560       if ($v_data['id'] == 0x06054b50) {
04561         $v_found = 1;
04562       }
04563 
04564       $v_pos = ftell($this->zip_fd);
04565     }
04566 
04567     // ----- Go back to the maximum possible size of the Central Dir End Record
04568     if (!$v_found) {
04569       $v_maximum_size = 65557; // 0xFFFF + 22;
04570       if ($v_maximum_size > $v_size)
04571         $v_maximum_size = $v_size;
04572       @fseek($this->zip_fd, $v_size-$v_maximum_size);
04573       if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
04574       {
04575         // ----- Error log
04576         PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
04577 
04578         // ----- Return
04579         return PclZip::errorCode();
04580       }
04581 
04582       // ----- Read byte per byte in order to find the signature
04583       $v_pos = ftell($this->zip_fd);
04584       $v_bytes = 0x00000000;
04585       while ($v_pos < $v_size)
04586       {
04587         // ----- Read a byte
04588         $v_byte = @fread($this->zip_fd, 1);
04589 
04590         // -----  Add the byte
04591         //$v_bytes = ($v_bytes << 8) | Ord($v_byte);
04592         // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number 
04593         // Otherwise on systems where we have 64bit integers the check below for the magic number will fail. 
04594         $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); 
04595 
04596         // ----- Compare the bytes
04597         if ($v_bytes == 0x504b0506)
04598         {
04599           $v_pos++;
04600           break;
04601         }
04602 
04603         $v_pos++;
04604       }
04605 
04606       // ----- Look if not found end of central dir
04607       if ($v_pos == $v_size)
04608       {
04609 
04610         // ----- Error log
04611         PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
04612 
04613         // ----- Return
04614         return PclZip::errorCode();
04615       }
04616     }
04617 
04618     // ----- Read the first 18 bytes of the header
04619     $v_binary_data = fread($this->zip_fd, 18);
04620 
04621     // ----- Look for invalid block size
04622     if (strlen($v_binary_data) != 18)
04623     {
04624 
04625       // ----- Error log
04626       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
04627 
04628       // ----- Return
04629       return PclZip::errorCode();
04630     }
04631 
04632     // ----- Extract the values
04633     $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
04634 
04635     // ----- Check the global size
04636     if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
04637 
04638           // ----- Removed in release 2.2 see readme file
04639           // The check of the file size is a little too strict.
04640           // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
04641           // While decrypted, zip has training 0 bytes
04642           if (0) {
04643       // ----- Error log
04644       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
04645                                'The central dir is not at the end of the archive.'
04646                                                    .' Some trailing bytes exists after the archive.');
04647 
04648       // ----- Return
04649       return PclZip::errorCode();
04650           }
04651     }
04652 
04653     // ----- Get comment
04654     if ($v_data['comment_size'] != 0) {
04655       $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
04656     }
04657     else
04658       $p_central_dir['comment'] = '';
04659 
04660     $p_central_dir['entries'] = $v_data['entries'];
04661     $p_central_dir['disk_entries'] = $v_data['disk_entries'];
04662     $p_central_dir['offset'] = $v_data['offset'];
04663     $p_central_dir['size'] = $v_data['size'];
04664     $p_central_dir['disk'] = $v_data['disk'];
04665     $p_central_dir['disk_start'] = $v_data['disk_start'];
04666 
04667     // TBC
04668     //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) {
04669     //}
04670 
04671     // ----- Return
04672     return $v_result;
04673   }

PclZip::privReadFileHeader ( &$  p_header  ) 

Definition at line 4277 of file pclzip.lib.php.

Referenced by privDeleteByRule().

04278   {
04279     $v_result=1;
04280 
04281     // ----- Read the 4 bytes signature
04282     $v_binary_data = @fread($this->zip_fd, 4);
04283     $v_data = unpack('Vid', $v_binary_data);
04284 
04285     // ----- Check signature
04286     if ($v_data['id'] != 0x04034b50)
04287     {
04288 
04289       // ----- Error log
04290       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
04291 
04292       // ----- Return
04293       return PclZip::errorCode();
04294     }
04295 
04296     // ----- Read the first 42 bytes of the header
04297     $v_binary_data = fread($this->zip_fd, 26);
04298 
04299     // ----- Look for invalid block size
04300     if (strlen($v_binary_data) != 26)
04301     {
04302       $p_header['filename'] = "";
04303       $p_header['status'] = "invalid_header";
04304 
04305       // ----- Error log
04306       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
04307 
04308       // ----- Return
04309       return PclZip::errorCode();
04310     }
04311 
04312     // ----- Extract the values
04313     $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
04314 
04315     // ----- Get filename
04316     $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
04317 
04318     // ----- Get extra_fields
04319     if ($v_data['extra_len'] != 0) {
04320       $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
04321     }
04322     else {
04323       $p_header['extra'] = '';
04324     }
04325 
04326     // ----- Extract properties
04327     $p_header['version_extracted'] = $v_data['version'];
04328     $p_header['compression'] = $v_data['compression'];
04329     $p_header['size'] = $v_data['size'];
04330     $p_header['compressed_size'] = $v_data['compressed_size'];
04331     $p_header['crc'] = $v_data['crc'];
04332     $p_header['flag'] = $v_data['flag'];
04333     $p_header['filename_len'] = $v_data['filename_len'];
04334 
04335     // ----- Recuperate date in UNIX format
04336     $p_header['mdate'] = $v_data['mdate'];
04337     $p_header['mtime'] = $v_data['mtime'];
04338     if ($p_header['mdate'] && $p_header['mtime'])
04339     {
04340       // ----- Extract time
04341       $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
04342       $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
04343       $v_seconde = ($p_header['mtime'] & 0x001F)*2;
04344 
04345       // ----- Extract date
04346       $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
04347       $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
04348       $v_day = $p_header['mdate'] & 0x001F;
04349 
04350       // ----- Get UNIX date format
04351       $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
04352 
04353     }
04354     else
04355     {
04356       $p_header['mtime'] = time();
04357     }
04358 
04359     // TBC
04360     //for(reset($v_data); $key = key($v_data); next($v_data)) {
04361     //}
04362 
04363     // ----- Set the stored filename
04364     $p_header['stored_filename'] = $p_header['filename'];
04365 
04366     // ----- Set the status field
04367     $p_header['status'] = "ok";
04368 
04369     // ----- Return
04370     return $v_result;
04371   }

PclZip::privSwapBackMagicQuotes (  ) 

Definition at line 5361 of file pclzip.lib.php.

Referenced by delete(), and properties().

05362   {
05363     $v_result=1;
05364 
05365     // ----- Look if function exists
05366     if (   (!function_exists("get_magic_quotes_runtime"))
05367             || (!function_exists("set_magic_quotes_runtime"))) {
05368       return $v_result;
05369         }
05370 
05371     // ----- Look if something to do
05372     if ($this->magic_quotes_status != -1) {
05373       return $v_result;
05374         }
05375 
05376         // ----- Swap back magic_quotes
05377         if ($this->magic_quotes_status == 1) {
05378           @set_magic_quotes_runtime($this->magic_quotes_status);
05379         }
05380 
05381     // ----- Return
05382     return $v_result;
05383   }

PclZip::privWriteCentralFileHeader ( &$  p_header  ) 

Definition at line 3067 of file pclzip.lib.php.

03068   {
03069     $v_result=1;
03070 
03071     // TBC
03072     //for(reset($p_header); $key = key($p_header); next($p_header)) {
03073     //}
03074 
03075     // ----- Transform UNIX mtime to DOS format mdate/mtime
03076     $v_date = getdate($p_header['mtime']);
03077     $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
03078     $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
03079 
03080 
03081     // ----- Packed data
03082     $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
03083                               $p_header['version'], $p_header['version_extracted'],
03084                           $p_header['flag'], $p_header['compression'],
03085                                                   $v_mtime, $v_mdate, $p_header['crc'],
03086                           $p_header['compressed_size'], $p_header['size'],
03087                           strlen($p_header['stored_filename']),
03088                                                   $p_header['extra_len'], $p_header['comment_len'],
03089                           $p_header['disk'], $p_header['internal'],
03090                                                   $p_header['external'], $p_header['offset']);
03091 
03092     // ----- Write the 42 bytes of the header in the zip file
03093     fputs($this->zip_fd, $v_binary_data, 46);
03094 
03095     // ----- Write the variable fields
03096     if (strlen($p_header['stored_filename']) != 0)
03097     {
03098       fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
03099     }
03100     if ($p_header['extra_len'] != 0)
03101     {
03102       fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
03103     }
03104     if ($p_header['comment_len'] != 0)
03105     {
03106       fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
03107     }
03108 
03109     // ----- Return
03110     return $v_result;
03111   }

PclZip::privWriteCentralHeader ( p_nb_entries,
p_size,
p_offset,
p_comment 
)

Definition at line 3120 of file pclzip.lib.php.

Referenced by privDeleteByRule().

03121   {
03122     $v_result=1;
03123 
03124     // ----- Packed data
03125     $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
03126                               $p_nb_entries, $p_size,
03127                                                   $p_offset, strlen($p_comment));
03128 
03129     // ----- Write the 22 bytes of the header in the zip file
03130     fputs($this->zip_fd, $v_binary_data, 22);
03131 
03132     // ----- Write the variable fields
03133     if (strlen($p_comment) != 0)
03134     {
03135       fputs($this->zip_fd, $p_comment, strlen($p_comment));
03136     }
03137 
03138     // ----- Return
03139     return $v_result;
03140   }

PclZip::privWriteFileHeader ( &$  p_header  ) 

Definition at line 3022 of file pclzip.lib.php.

03023   {
03024     $v_result=1;
03025 
03026     // ----- Store the offset position of the file
03027     $p_header['offset'] = ftell($this->zip_fd);
03028 
03029     // ----- Transform UNIX mtime to DOS format mdate/mtime
03030     $v_date = getdate($p_header['mtime']);
03031     $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
03032     $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
03033 
03034     // ----- Packed data
03035     $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
03036                               $p_header['version_extracted'], $p_header['flag'],
03037                           $p_header['compression'], $v_mtime, $v_mdate,
03038                           $p_header['crc'], $p_header['compressed_size'],
03039                                                   $p_header['size'],
03040                           strlen($p_header['stored_filename']),
03041                                                   $p_header['extra_len']);
03042 
03043     // ----- Write the first 148 bytes of the header in the archive
03044     fputs($this->zip_fd, $v_binary_data, 30);
03045 
03046     // ----- Write the variable fields
03047     if (strlen($p_header['stored_filename']) != 0)
03048     {
03049       fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
03050     }
03051     if ($p_header['extra_len'] != 0)
03052     {
03053       fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
03054     }
03055 
03056     // ----- Return
03057     return $v_result;
03058   }

PclZip::properties (  ) 

Definition at line 1089 of file pclzip.lib.php.

01090   {
01091 
01092     // ----- Reset the error handler
01093     $this->privErrorReset();
01094 
01095     // ----- Magic quotes trick
01096     $this->privDisableMagicQuotes();
01097 
01098     // ----- Check archive
01099     if (!$this->privCheckFormat()) {
01100       $this->privSwapBackMagicQuotes();
01101       return(0);
01102     }
01103 
01104     // ----- Default properties
01105     $v_prop = array();
01106     $v_prop['comment'] = '';
01107     $v_prop['nb'] = 0;
01108     $v_prop['status'] = 'not_exist';
01109 
01110     // ----- Look if file exists
01111     if (@is_file($this->zipname))
01112     {
01113       // ----- Open the zip file
01114       if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
01115       {
01116         $this->privSwapBackMagicQuotes();
01117         
01118         // ----- Error log
01119         PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
01120 
01121         // ----- Return
01122         return 0;
01123       }
01124 
01125       // ----- Read the central directory informations
01126       $v_central_dir = array();
01127       if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
01128       {
01129         $this->privSwapBackMagicQuotes();
01130         return 0;
01131       }
01132 
01133       // ----- Close the zip file
01134       $this->privCloseFd();
01135 
01136       // ----- Set the user attributes
01137       $v_prop['comment'] = $v_central_dir['comment'];
01138       $v_prop['nb'] = $v_central_dir['entries'];
01139       $v_prop['status'] = 'ok';
01140     }
01141 
01142     // ----- Magic quotes trick
01143     $this->privSwapBackMagicQuotes();
01144 
01145     // ----- Return
01146     return $v_prop;
01147   }


Member Data Documentation

PclZip::$error_code = 1

Definition at line 199 of file pclzip.lib.php.

PclZip::$error_string = ''

Definition at line 200 of file pclzip.lib.php.

PclZip::$magic_quotes_status

Definition at line 205 of file pclzip.lib.php.

PclZip::$zip_fd = 0

Definition at line 196 of file pclzip.lib.php.

PclZip::$zipname = ''

Definition at line 193 of file pclzip.lib.php.


The documentation for this class was generated from the following file: