zip.php
Table of Contents
Functions
- zip() : string
- Creates a zip archive from one or more files and/or directories.
Functions
zip()
Creates a zip archive from one or more files and/or directories.
zip(string|array<string|int, string> $paths[, string|null $outputPath = null ][, string|null $compression = CompressionType::ZIP ][, string|null $preserveRoot = null ]) : string
This function supports adding multiple paths (files or directories) to a zip archive, with a per-entry compression method. It can preserve the root directory structure inside the archive, and generates a unique temporary archive if no output path is specified.
Empty directories are preserved in the archive.
Parameters
- $paths : string|array<string|int, string>
-
Absolute path(s) to file(s) or directory(ies) to include in the archive.
- $outputPath : string|null = null
-
Optional full path to the final archive file to create. If null, an automatic unique filename with timestamp is generated in the system temp directory.
- $compression : string|null = CompressionType::ZIP
-
Per-entry compression method. Supported values are CompressionType::ZIP (DEFLATE, the default) and CompressionType::NONE (stored, no compression).
- $preserveRoot : string|null = null
-
If set, paths inside the archive will be stored relative to this directory, allowing to preserve directory structure when extracting. Must be an absolute path.
Tags
Return values
string —Returns the full path to the created zip archive file.