Unzips the given ZIP file to the destination directory
Example
// Unzip a file
$zip = $config->paths->cache . "my-file.zip";
$dst = $config->paths->cache . "my-files/";
$items = $files->unzip($zip, $dst);
if(count($items)) {
// $items is an array of filenames that were unzipped into $dst
}
Usage
// basic usage
$array = $files->unzip(string $zipFile, string $destinationPath);
// usage with all arguments
$array = $files->unzip(string $zipFile, string $destinationPath, array $options = []);
Arguments
| Name | Type(s) | Description |
|---|
$zipFile | string | ZIP file to extract |
$destinationPath | string | Directory where files should be unzipped into. Directory is created if it doesn't exist. |
$options (optional) | array | Options to modify default behavior 3.0.254+: extractFiles (array): Filenames or regex patterns for files to extract, ignoring all others. Default:[]extractExtensions (array): Only extract these file extensions, ignoring all others. Default:[]ignoreFiles (array): Basenames or regex patterns matching basenames to skip/ignore Default:[ '.DS_Store', '__MACOSX' ]ignoreExtensions (array): Extensions to skip/ignore for files in the ZIP Default:[ 'zip' ]minFiles (int): Minimum number files that must be present inside the ZIP for it to be valid. Default:1maxFiles (int): Maximum number of files allowed in ZIP Default:1000maxDepth (int): $maxDepth Maximum allowed folder/directory depth in ZIP Default:8maxFileMegabytes (int): Maximum allowed uncompressed size of any individual file in ZIP, in MB. Default:20maxTotalMegabytes (int): Maximum allowed total uncompressed size of all files in ZIP, in MB. Default:100maxErrors (int): Maximum number of errors to report Default:10requireFiles (array): File names or regex patterns that must be present in at least one file for ZIP to be valid. For example !\.json$! would require that a .json file is present in the ZIP. default=[]fatalFiles (array): Strings or regex patterns that when matched, cause entire ZIP to fail validation.
If not given a regex, it matches any part of the filename. Default:[]maxCompRatio (int): Max allowed compression ratio or 0 to ignore Default:0test (bool|string): Do not actually unzip but return the filenames that would be unzipped.
Specify 'verbose' rather than true to return verbose array of info instead of filenames. Default:false- For the
extractFiles, ignoreFiles, requireFiles and fatalFiles options, You can optionally specify a regex pattern by using a ! as your regex starting and ending delimiter.
|
Return value
arrayReturns an array of filenames (excluding $dst) that were unzipped.
Exceptions
Method can throw exceptions on error:
See Also
$files methods and properties
API reference based on ProcessWire core version 3.0.253