unzip.php
Table of Contents
Functions
- unzip() : true|array<string|int, string>
- Extracts a zip archive into a destination directory.
Functions
unzip()
Extracts a zip archive into a destination directory.
unzip(string $zipFile, string $outputPath[, array{dryRun?: bool, overwrite?: bool, maxEntries?: int|null, maxSize?: int|null, keepPermissions?: bool} $options = [] ]) : true|array<string|int, string>
This function mirrors untar(). It guards against path traversal (Zip Slip) and decompression bombs, can preview the contents without writing anything (dry run), and can refuse to overwrite existing files.
Parameters
- $zipFile : string
-
Path to the zip archive to extract.
- $outputPath : string
-
Directory where the archive is extracted. Created if missing.
- $options : array{dryRun?: bool, overwrite?: bool, maxEntries?: int|null, maxSize?: int|null, keepPermissions?: bool} = []
-
Optional flags, keyed by ZipOption:
- dryRun: If true, no file is written; returns the list of file entries that would be extracted (directory entries excluded). Default: false.
- overwrite: If false, extraction fails when a target file already exists. Default: true.
- maxEntries: If a positive integer, the archive is rejected when it declares more entries than this limit (decompression-bomb guard). Default: null (no limit).
- maxSize: If a positive integer, the archive is pre-scanned and rejected before any file is written when the sum of the entries' uncompressed sizes exceeds this limit (decompression-bomb guard). Default: null (no limit).
- keepPermissions: If true, restores the Unix file mode stored in each entry's external
attributes (
OPSYS_UNIX) viachmod(). Entries without Unix permissions are left with the default mode. Best-effort: a failingchmod()is ignored. Default: false.
Tags
Return values
true|array<string|int, string> —Returns true on successful extraction, or the list of file entries (relative to the archive root) when dryRun is enabled.