$files→zip()
Creates a ZIP file
Example
// Create zip of all files in directory $dir to file $zip $dir = $config->paths->cache . "my-files/"; $zip = $config->paths->cache . "my-file.zip"; $result = $files->zip($zip, $dir); echo "<h3>These files were added to the ZIP:</h3>"; foreach($result['files'] as $file) { echo "<li>" $sanitizer->entities($file) . "</li>"; } if(count($result['errors'])) { echo "<h3>There were errors:</h3>"; foreach($result['errors'] as $error) { echo "<li>" . $sanitizer->entities($error) . "</li>"; } }Usage
// basic usage $array = $files->zip(string $zipfile, $files); // usage with all arguments $array = $files->zip(string $zipfile, $files, array $options = []);Arguments
| Name | Type(s) | Description |
|---|---|---|
$zipfile | string | Full path and filename to create or update (i.e. /path/to/myfile.zip) |
$files | array string | Array of files to add (full path and filename), or directory (string) to add. If given a directory, it will recursively add everything in that directory. |
$options (optional) | array | Associative array of options to modify default behavior:
|
Return value
arrayReturns associative array of:
files(array): all files that were addederrors(array): files that failed to add, if any
Exceptions
Method can throw exceptions on error:
WireException- Original ZIP file creation error conditions result in WireException being thrown.
See Also
API reference based on ProcessWire core version 3.0.255