class Zip implements ArchiverInterface (View source)

Defines an archiver implementation for .zip files.

Properties

protected ZipArchive $zip

The underlying ZipArchive instance that does the heavy lifting.

Methods

__construct(string $file_path)

Constructs a Zip object.

$this
add(string $file_path)

Adds the specified file or directory to the archive.

$this
remove($file_path)

Removes the specified file from the archive.

$this
extract(string $path, array $files = [])

Extracts multiple files in the archive to the specified path.

array
listContents()

Lists all files in the archive.

ZipArchive
getArchive()

Retrieves the zip engine itself.

Details

__construct(string $file_path)

Constructs a Zip object.

Parameters

string $file_path

The full system path of the archive to manipulate. Only local files are supported. If the file does not yet exist, it will be created if appropriate.

Exceptions

ArchiverException

$this add(string $file_path)

Adds the specified file or directory to the archive.

Parameters

string $file_path

The full system path of the file or directory to add. Only local files and directories are supported.

Return Value

$this

The called object.

$this remove($file_path)

Removes the specified file from the archive.

Parameters

$file_path

Return Value

$this

The called object.

$this extract(string $path, array $files = [])

Extracts multiple files in the archive to the specified path.

Parameters

string $path

A full system path of the directory to which to extract files.

array $files

Optionally specify a list of files to be extracted. Files are relative to the root of the archive. If not specified, all files in the archive will be extracted.

Return Value

$this

The called object.

array listContents()

Lists all files in the archive.

Return Value

array

An array of file names relative to the root of the archive.

ZipArchive getArchive()

Retrieves the zip engine itself.

In some cases it may be necessary to directly access the underlying ZipArchive object for implementation-specific logic. This is for advanced use only as it is not shared by other implementations of ArchiveInterface.

Return Value

ZipArchive

The ZipArchive object used by this object.