The ZipArchive class
Introduction
(PHP 5 >= 5.2.0, PHP 7, PECL zip >= 1.1.0)
A file archive, compressed with Zip.
Class synopsis
ZipArchive implements Countable {
/* Properties */
int $lastId;
int $status;
int $statusSys;
int $numFiles;
string $filename;
string $comment;
/* Methods */
public addEmptyDir ( string $dirname [, int $flags = 0 ] ) : bool
public addFile ( string $filename [, string $entryname = null [, int $start = 0 [, int $length = 0 [, int $flags = ZipArchive::FL_OVERWRITE ]]]] ) : bool
public addFromString ( string $name , string $contents [, int $flags = ZipArchive::FL_OVERWRITE ] ) : bool
public addGlob ( string $pattern [, int $flags = 0 [, array $options = array() ]] ) : array|false
public addPattern ( string $pattern [, string $path = "." [, array $options = array() ]] ) : array|false
public close ( ) : bool
public count ( ) : int
public deleteIndex ( int $index ) : bool
public deleteName ( string $name ) : bool
public extractTo ( string $destination [, mixed $entries ] ) : bool
public getArchiveComment ([ int $flags ] ) : string|false
public getCommentIndex ( int $index [, int $flags ] ) : string|false
public getCommentName ( string $name [, int $flags ] ) : string|false
public GetExternalAttributesIndex ( int $index , int &$opsys , int &$attr [, int $flags ] ) : bool
public getExternalAttributesName ( string $name , int &$opsys , int &$attr [, int $flags ] ) : bool
public getFromIndex ( int $index [, int $length = 0 [, int $flags ]] ) : string|false
public getFromName ( string $name [, int $length = 0 [, int $flags ]] ) : string|false
public getNameIndex ( int $index [, int $flags ] ) : string|false
public getStatusString ( ) : string|false
public getStream ( string $name ) : resource|false
public isCompressionMethodSupported ( int $method [, bool $encode = true ] ) : bool
public isEncryptionMethodSupported ( int $method [, bool $encode = true ] ) : bool
public locateName ( string $name [, int $flags ] ) : int|false
public open ( string $filename [, int $flags ] ) : mixed
public registerCancelCallback ( callable $callback ) : bool
public registerProgressCallback ( float $rate , callable $callback ) : bool
public renameIndex ( int $index , string $newname ) : bool
public renameName ( string $name , string $newname ) : bool
public replaceFile ( string $filename , int $index [, int $start = 0 [, int $length = 0 [, int $flags = 0 ]]] ) : bool
public setArchiveComment ( string $comment ) : bool
public setCommentIndex ( int $index , string $comment ) : bool
public setCommentName ( string $name , string $comment ) : bool
public setCompressionIndex ( int $index , int $comp_method [, int $comp_flags = 0 ] ) : bool
public setCompressionName ( string $name , int $comp_method [, int $comp_flags = 0 ] ) : bool
public setEncryptionIndex ( int $index , int $method [, string $password ] ) : bool
public setEncryptionName ( string $name , int $method [, string $password ] ) : bool
public setExternalAttributesIndex ( int $index , int $opsys , int $attr [, int $flags ] ) : bool
public setExternalAttributesName ( string $name , int $opsys , int $attr [, int $flags ] ) : bool
public setMtimeIndex ( int $index , int $timestamp [, int $flags ] ) : bool
public setMtimeName ( string $name , int $timestamp [, int $flags ] ) : bool
public setPassword ( string $password ) : bool
public statIndex ( int $index [, int $flags ] ) : array|false
public statName ( string $name [, int $flags ] ) : array|false
public unchangeAll ( ) : bool
public unchangeArchive ( ) : bool
public unchangeIndex ( int $index ) : bool
public unchangeName ( string $name ) : bool}
Properties
- lastId
-
Index value of last added entry (file or directory). Available as of PHP 8.0.0 and PECL zip 1.18.0.
- status
-
Status of the Zip Archive. Available for closed archive, as of PHP 8.0.0 and PECL zip 1.18.0.
- statusSys
-
System status of the Zip Archive. Available for closed archive, as of PHP 8.0.0 and PECL zip 1.18.0.
- numFiles
-
Number of files in archive
- filename
-
File name in the file system
- comment
-
Comment for the archive
Table of Contents
- ZipArchive::addEmptyDir — Add a new directory
- ZipArchive::addFile — Adds a file to a ZIP archive from the given path
- ZipArchive::addFromString — Add a file to a ZIP archive using its contents
- ZipArchive::addGlob — Add files from a directory by glob pattern
- ZipArchive::addPattern — Add files from a directory by PCRE pattern
- ZipArchive::close — Close the active archive (opened or newly created)
- ZipArchive::count — Counts the number of files in the archive
- ZipArchive::deleteIndex — Delete an entry in the archive using its index
- ZipArchive::deleteName — Delete an entry in the archive using its name
- ZipArchive::extractTo — Extract the archive contents
- ZipArchive::getArchiveComment — Returns the Zip archive comment
- ZipArchive::getCommentIndex — Returns the comment of an entry using the entry index
- ZipArchive::getCommentName — Returns the comment of an entry using the entry name
- ZipArchive::getExternalAttributesIndex — Retrieve the external attributes of an entry defined by its index
- ZipArchive::getExternalAttributesName — Retrieve the external attributes of an entry defined by its name
- ZipArchive::getFromIndex — Returns the entry contents using its index
- ZipArchive::getFromName — Returns the entry contents using its name
- ZipArchive::getNameIndex — Returns the name of an entry using its index
- ZipArchive::getStatusString — Returns the status error message, system and/or zip messages
- ZipArchive::getStream — Get a file handler to the entry defined by its name (read only)
- ZipArchive::isCompressionMethodSupported — Check if a compression method is supported by libzip
- ZipArchive::isEncryptionMethodSupported — Check if a encryption method is supported by libzip
- ZipArchive::locateName — Returns the index of the entry in the archive
- ZipArchive::open — Open a ZIP file archive
- ZipArchive::registerCancelCallback — Register a callback to allow cancellation during archive close.
- ZipArchive::registerProgressCallback — Register a callback to provide updates during archive close.
- ZipArchive::renameIndex — Renames an entry defined by its index
- ZipArchive::renameName — Renames an entry defined by its name
- ZipArchive::replaceFile — Replace file in ZIP archive with a given path
- ZipArchive::setArchiveComment — Set the comment of a ZIP archive
- ZipArchive::setCommentIndex — Set the comment of an entry defined by its index
- ZipArchive::setCommentName — Set the comment of an entry defined by its name
- ZipArchive::setCompressionIndex — Set the compression method of an entry defined by its index
- ZipArchive::setCompressionName — Set the compression method of an entry defined by its name
- ZipArchive::setEncryptionIndex — Set the encryption method of an entry defined by its index
- ZipArchive::setEncryptionName — Set the encryption method of an entry defined by its name
- ZipArchive::setExternalAttributesIndex — Set the external attributes of an entry defined by its index
- ZipArchive::setExternalAttributesName — Set the external attributes of an entry defined by its name
- ZipArchive::setMtimeIndex — Set the modification time of an entry defined by its index
- ZipArchive::setMtimeName — Set the modification time of an entry defined by its name
- ZipArchive::setPassword — Set the password for the active archive
- ZipArchive::statIndex — Get the details of an entry defined by its index
- ZipArchive::statName — Get the details of an entry defined by its name
- ZipArchive::unchangeAll — Undo all changes done in the archive
- ZipArchive::unchangeArchive — Revert all global changes done in the archive
- ZipArchive::unchangeIndex — Revert all changes done to an entry at the given index
- ZipArchive::unchangeName — Revert all changes done to an entry with the given name
© 1997–2020 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/class.ziparchive.php