zipDirectory.php
Table of Contents
Functions
- zipDirectory() : string
- Creates a zip archive from a directory.
Functions
zipDirectory()
Creates a zip archive from a directory.
zipDirectory(string $directory[, string|null $compression = CompressionType::ZIP ][, string|null $outputPath = null ][, array<string|int, mixed> $options = [] ]) : string
This function creates a zip archive from the given directory. It supports filtering
files by exclude patterns, by a callback filter function, and adding optional metadata
saved as .metadata.json inside the archive.
If no filters or metadata are provided, it simply creates the archive directly from the directory (preserving its root). Otherwise, it copies the filtered files to a temporary directory and archives from there.
Parameters
- $directory : string
-
The source directory to archive.
- $compression : string|null = CompressionType::ZIP
-
Per-entry compression method (CompressionType::ZIP — DEFLATE, default — or CompressionType::NONE — stored).
- $outputPath : string|null = null
-
Optional output archive path. If null, defaults to the directory name plus the
.zipextension. - $options : array<string|int, mixed> = []
-
Additional options:
- exclude => string[] list of glob patterns or file names to exclude
- filter => callable|null a function (string $filepath): bool
- metadata => array<string, string> extra metadata to embed in
.metadata.json
Tags
Return values
string —Returns the full path to the created archive file.