Method PclZip::extract()
Overview
This method extract the files (and folders) archived in the PKZIP file.Synopsis
PclZip::extract([options list])
Arguments
options list :
This method support the following optional arguments :
- PCLZIP_OPT_PATH
- PCLZIP_OPT_REMOVE_PATH
- PCLZIP_OPT_REMOVE_ALL_PATH
- PCLZIP_OPT_ADD_PATH
- PCLZIP_CB_PRE_EXTRACT
- PCLZIP_CB_POST_EXTRACT
- PCLZIP_OPT_SET_CHMOD
- PCLZIP_OPT_BY_NAME
- PCLZIP_OPT_BY_EREG
- PCLZIP_OPT_BY_PREG
- PCLZIP_OPT_BY_INDEX
- PCLZIP_OPT_EXTRACT_AS_STRING
- PCLZIP_OPT_EXTRACT_IN_OUTPUT
- PCLZIP_OPT_REPLACE_NEWER
- PCLZIP_OPT_STOP_ON_ERROR
- PCLZIP_OPT_EXTRACT_DIR_RESTRICTION
- PCLZIP_OPT_TEMP_FILE_THRESHOLD
- PCLZIP_OPT_TEMP_FILE_ON
- PCLZIP_OPT_TEMP_FILE_OFF
See chapter "Optional arguments" for more informations.Returned values
0
On error.
an array
An array with the extracted files.
Notice that if one file extraction fail, the full extraction does not fail. The method does not return an error, but the file status is set with the error reason.
(See "Returned values ")Description
This method extract all or part of the files contained in the PKZIP file.
Filtering can be done by the optional arguments PCLZIP_OPT_BY_NAME, PCLZIP_OPT_BY_EREG, PCLZIP_OPT_BY_PREG and PCLZIP_OPT_BY_INDEX.
Other optional arguments gives the ability to extract in a specific folder (PCLZIP_OPT_PATH, PCLZIP_OPT_ADD_PATH), remove the archived path (PCLZIP_OPT_REMOVE_ALL_PATH) or remove only a prefix of this path (PCLZIP_OPT_REMOVE_PATH).
When extracting few files, or small files, the option PCLZIP_OPT_EXTRACT_AS_STRING gives the ability to extract the content of a file in the returned array rather than writing it in a file. This can be usefull for example for extracting the readme file of an archived package, before doing the full extract.
An other option is to directly send the file content to the standard output (PCLZIP_OPT_EXTRACT_IN_OUTPUT).Sample
require_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
if ($archive->extract() == 0) {
die("Error : ".$archive->errorInfo(true));
}
In this sample all the files of the archive are extracted in the current directory.
include('pclzip.lib.php');
$archive = new PclZip('archive.zip');
if ($archive->extract(PCLZIP_OPT_PATH, 'data',
PCLZIP_OPT_REMOVE_PATH, 'install/release') == 0) {
die("Error : ".$archive->errorInfo(true));
}
In this sample all the files are extracted in the folder 'data'. All the files, with path prefix 'install/release', are extracted in 'data', not in 'data/install/release'.
| [Back to Methods List] |




