PhpConcept

Developers Tools

  • Increase font size
  • Default font size
  • Decrease font size
Home PclZip User Guide

PclZip User Guide - PCLZIP_CB_POST_EXTRACT

Print PDF

PCLZIP_CB_POST_EXTRACT

This optional arguments gives you the ability to add a specific processing while extrating an archive by calling a "call-back" function after the extraction of each archived file. The call-back function PCLZIP_CB_POST_EXTRACT can not modify the extraction process, but allow to perform user defined actions on the extracted file, like renaming or removing.

The 'call-back' function, given as a value of the argument, must respect the following synopsis :

function myCallBack($p_event, &$p_header)
{
[... Your specific code ...]
return $result;
}

When the method call the call-back function, it gives the following arguments :
- $p_event : the identity of the call-back argument (here PCLZIP_CB_POST_EXTRACT). This is usefull when you want to use the same function for different call-back actions.
- $p_header : the description of the file that was extracted, specifically the name of the extracted file and the status of the extraction. The array fields are described in the chapter 'Returned Values'.
The function can not modify the $p_header array because the extraction is alreay done.
The function must return 2 or 1 ($result). Other values are reserved for futur use. When the function returns 1, the extraction resume normally. If the function returns 2, the extraction is normally stopped, no more files are extracted.

  function myPreExtractCallBack($p_event, &$p_header) { ... }

  function 
myPostExtractCallBack($p_event, &$p_header)
  {
    
// ----- look for valid extraction
    
if ($p_header['status'] == 'ok') {
      
// ----- read the file to the standard output
      
readfile($p_header['filename']);
      
// ----- delete the file
      
unlink($p_header['filename'])
    }
  }

  
$list $archive->extract(PCLZIP_OPT_PATH'temp',
                            
PCLZIP_CB_PRE_EXTRACT'myPreExtractCallBack',
                            
PCLZIP_CB_POST_EXTRACT'myPostExtractCallBack');
 

In this sample the call-back function send to the standard output all the correctly extracted files and then destroy the file before extracting the next one.
Notice that since release 2.1, the optional argument PCLZIP_OPT_EXTRACT_IN_OUTPUT, gives a better result, because no temporary files are created in the file system.

 

 

[Optional Arguments List]

 

Last Updated on Friday, 18 December 2009 13:49