PCLZIP_CB_PRE_ADD
This call back feature is called just before the add of each file in the archive. By using this call back you can :
- modify the filename and path that will be stored in the archive (rather than keeping the real name and path),
- skip the add of one (or several) selected file(s) during the archive process.This call-back is called after the actions trigged by the optional arguments PCLZIP_OPT_PATH, PCLZIP_OPT_ADD_PATH, PCLZIP_OPT_REMOVE_PATH or PCLZIP_OPT_REMOVE_ALL_PATH, but before the check of the filename length..
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_PRE_ADD). This is usefull when you want to use the same function for different call-back actions.
- $p_header : the description of the file that will be added. This is an array which contains informations in several fields. The most interesting are the archived file name and the destination file name of the added file. The array fields are described in the chapter 'Returned Values'.
The function can only modify the field 'filename' of $p_header array. This field is the destination filename of the added file. This gives the ability to change the destination of the added file. The other fields are read-only.
The function must return 1 or 0 ($result). Other values are reserved for futur use. If the function returns 1, then the add is resumed (with the potentially modified destination filename). If the result is 0 the file add is skipped, and the method process will go for the next file to add.function myPreAddCallBack($p_event, &$p_header)
{
$info = pathinfo($p_header['stored_filename']);
// ----- bak files are skipped
if ($info['extension'] == 'bak') {
return 0;
}
// ----- jpg files are add with an images folder
else if ($info['extension'] == 'jpg') {
$p_header['stored_filename'] = 'images/'.$info['basename'];
return 1;
}
// ----- all other files are simply added
else {
return 1;
}
}
$list = $archive->add(PCLZIP_CB_PRE_ADD, 'myPreAddCallBack');In this sample the call-back function does not archive the files with extension 'bak', archive the files with extension 'jpg' in an 'images'folder and archive all the other files without any changes.
| [Optional Arguments List] |




