ZipArchive
class ZipArchive implements Countable (View source)
A file archive, compressed with Zip.
Constants
LIBZIP_VERSION
Since: 7.4.3
|
Zip library version |
CREATE |
Create the archive if it does not exist. |
EXCL |
Error if archive already exists. |
CHECKCONS |
Perform additional consistency checks on the archive, and error if they fail. |
OVERWRITE |
Always start a new archive, this mode will overwrite the file if
it already exists. |
FL_NOCASE |
Ignore case on name lookup |
FL_NODIR |
Ignore directory component |
FL_COMPRESSED |
Read compressed data |
FL_UNCHANGED |
Use original data, ignoring changes. |
FL_RECOMPRESS |
|
FL_ENCRYPTED |
|
FL_OVERWRITE |
|
FL_LOCAL |
|
FL_CENTRAL |
|
EM_TRAD_PKWARE |
|
EM_UNKNOWN |
|
CM_DEFAULT |
better of deflate or store. |
CM_STORE |
stored (uncompressed). |
CM_SHRINK |
shrunk |
CM_REDUCE_1 |
reduced with factor 1 |
CM_REDUCE_2 |
reduced with factor 2 |
CM_REDUCE_3 |
reduced with factor 3 |
CM_REDUCE_4 |
reduced with factor 4 |
CM_IMPLODE |
imploded |
CM_DEFLATE |
deflated |
CM_DEFLATE64 |
deflate64 |
CM_PKWARE_IMPLODE |
PKWARE imploding |
CM_BZIP2 |
BZIP2 algorithm |
CM_LZMA |
|
CM_TERSE |
|
CM_LZ77 |
|
CM_WAVPACK |
|
CM_PPMD |
|
ER_OK |
No error. |
ER_MULTIDISK |
Multi-disk zip archives not supported. |
ER_RENAME |
Renaming temporary file failed. |
ER_CLOSE |
Closing zip archive failed |
ER_SEEK |
Seek error |
ER_READ |
Read error |
ER_WRITE |
Write error |
ER_CRC |
CRC error |
ER_ZIPCLOSED |
Containing zip archive was closed |
ER_NOENT |
No such file. |
ER_EXISTS |
File already exists |
ER_OPEN |
Can't open file |
ER_TMPOPEN |
Failure to create temporary file. |
ER_ZLIB |
Zlib error |
ER_MEMORY |
Memory allocation failure |
ER_CHANGED |
Entry has been changed |
ER_COMPNOTSUPP |
Compression method not supported. |
ER_EOF |
Premature EOF |
ER_INVAL |
Invalid argument |
ER_NOZIP |
Not a zip archive |
ER_INTERNAL |
Internal error |
ER_INCONS |
Zip archive inconsistent |
ER_REMOVE |
Can't remove file |
ER_DELETED |
Entry has been deleted |
EM_NONE
Since: 7.2
|
No encryption |
EM_AES_128
Since: 7.2
|
AES 128 encryption |
EM_AES_192
Since: 7.2
|
AES 192 encryption |
EM_AES_256
Since: 7.2
|
AES 256 encryption |
RDONLY
Since: 7.4.3
|
Open archive in read only mode |
FL_ENC_GUESS
Since: 7.0.8
|
Guess string encoding (is default) |
FL_ENC_RAW
Since: 7.0.8
|
Get unmodified string |
FL_ENC_STRICT
Since: 7.0.8
|
Follow specification strictly |
FL_ENC_UTF_8
Since: 7.0.8
|
String is UTF-8 encoded |
FL_ENC_CP437
Since: 7.0.8
|
String is CP437 encoded |
CM_LZMA2
Since: 7.4.3
|
LZMA2 algorithm |
CM_XZ
Since: 7.4.3
|
XZ algorithm |
ER_ENCRNOTSUPP
Since: 7.4.3
|
Encryption method not support |
ER_RDONLY
Since: 7.4.3
|
Read-only archive |
ER_NOPASSWD
Since: 7.4.3
|
No password provided |
ER_WRONGPASSWD
Since: 7.4.3
|
Wrong password provided |
ER_OPNOTSUPP
Since: 7.4.3
|
Operation not supported |
ER_INUSE
Since: 7.4.3
|
Resource still in use |
ER_TELL
Since: 7.4.3
|
Tell error |
ER_COMPRESSED_DATA
Since: 7.4.3
|
Compressed data invalid |
ER_CANCELLED
Since: 7.4.3
|
Operation cancelled |
OPSYS_DOS
Since: 5.6
|
|
OPSYS_AMIGA
Since: 5.6
|
|
OPSYS_OPENVMS
Since: 5.6
|
|
OPSYS_UNIX
Since: 5.6
|
|
OPSYS_VM_CMS
Since: 5.6
|
|
OPSYS_ATARI_ST
Since: 5.6
|
|
OPSYS_OS_2
Since: 5.6
|
|
OPSYS_MACINTOSH
Since: 5.6
|
|
OPSYS_Z_SYSTEM
Since: 5.6
|
|
OPSYS_Z_CPM
Since: 5.6
|
|
OPSYS_WINDOWS_NTFS
Since: 5.6
|
|
OPSYS_MVS
Since: 5.6
|
|
OPSYS_VSE
Since: 5.6
|
|
OPSYS_ACORN_RISC
Since: 5.6
|
|
OPSYS_VFAT
Since: 5.6
|
|
OPSYS_ALTERNATE_MVS
Since: 5.6
|
|
OPSYS_BEOS
Since: 5.6
|
|
OPSYS_TANDEM
Since: 5.6
|
|
OPSYS_OS_400
Since: 5.6
|
|
OPSYS_OS_X
Since: 5.6
|
|
OPSYS_CPM |
|
OPSYS_DEFAULT
Since: 5.6
|
|
FL_OPEN_FILE_NOW |
|
CM_ZSTD |
|
ER_DATA_LENGTH |
|
ER_NOT_ALLOWED |
|
AFL_RDONLY |
|
AFL_IS_TORRENTZIP |
|
AFL_WANT_TORRENTZIP |
|
AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE |
|
LENGTH_TO_END |
|
LENGTH_UNCHECKED |
|
Properties
int | $status | Status of the Zip Archive |
|
int | $statusSys | System status of the Zip Archive |
|
int | $numFiles | Number of files in archive |
|
string | $filename | File name in the file system |
|
string | $comment | Comment for the archive |
|
int | $lastId |
Methods
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Open a ZIP file archive
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Close the active archive (opened or newly created)
(PHP 7 >= 7.2.0, PECL zip >= 1.15.0)
Counts the number of files in the archive.
Returns the status error message, system and/or zip messages
(PHP 5 >= 5.2.0, PECL zip >= 1.8.0)
Add a new directory
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Add a file to a ZIP archive using its contents
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Adds a file to a ZIP archive from the given path
(PHP 5 >= 5.3.0, PECL zip >= 1.9.0)
Add files from a directory by glob pattern
(PHP 5 >= 5.3.0, PECL zip >= 1.9.0)
Add files from a directory by PCRE pattern
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
Renames an entry defined by its index
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
Renames an entry defined by its name
(PHP 5 >= 5.2.0, PECL zip >= 1.4.0)
Set the comment of a ZIP archive
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Returns the Zip archive comment
(PHP 5 >= 5.2.0, PECL zip >= 1.4.0)
Set the comment of an entry defined by its index
(PHP 5 >= 5.2.0, PECL zip >= 1.4.0)
Set the comment of an entry defined by its name
Set the compression method of an entry defined by its index
Set the compression method of an entry defined by its name https://secure.php.net/manual/en/ziparchive.setcompressionname.php
Set the encryption method of an entry defined by its index
Set the encryption method of an entry defined by its name
(PHP 5 >= 5.6.0, PECL zip >= 1.12.0)
(PHP 5 >= 5.2.0, PECL zip >= 1.4.0)
Returns the comment of an entry using the entry index
(PHP 5 >= 5.2.0, PECL zip >= 1.4.0)
Returns the comment of an entry using the entry name
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
delete an entry in the archive using its index
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
delete an entry in the archive using its name
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
Get the details of an entry defined by its name.
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Get the details of an entry defined by its index.
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
Returns the index of the entry in the archive
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
Returns the name of an entry using its index
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Revert all global changes done in the archive.
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Undo all changes done in the archive
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Revert all changes done to an entry at the given index
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
Revert all changes done to an entry with the given name.
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Extract the archive contents
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Returns the entry contents using its name
(PHP 5 >= 5.2.0, PECL zip >= 1.3.0)
Returns the entry contents using its index
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Get a file handler to the entry defined by its name (read only).
(PHP 8 >= 8.2.0, PECL zip >= 1.20.0)
Get a file handler to the entry defined by its index (read only)
Set the external attributes of an entry defined by its name
Retrieve the external attributes of an entry defined by its name
Set the external attributes of an entry defined by its index
Retrieve the external attributes of an entry defined by its index
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
Details
int|bool
open(string $filename, int $flags = null)
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Open a ZIP file archive
bool
close()
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Close the active archive (opened or newly created)
int
count()
(PHP 7 >= 7.2.0, PECL zip >= 1.15.0)
Counts the number of files in the archive.
string
getStatusString()
Returns the status error message, system and/or zip messages
bool
addEmptyDir(string $dirname, int $flags)
(PHP 5 >= 5.2.0, PECL zip >= 1.8.0)
Add a new directory
bool
addFromString(string $name, string $content, int $flags = 8192)
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Add a file to a ZIP archive using its contents
bool
addFile(string $filepath, string $entryname = null, int $start = 0, int $length = 0, int $flags = 8192)
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Adds a file to a ZIP archive from the given path
array|false
addGlob(string $pattern, int $flags = 0, array $options = [])
(PHP 5 >= 5.3.0, PECL zip >= 1.9.0)
Add files from a directory by glob pattern
array|false
addPattern(string $pattern, string $path = '.', array $options = [])
(PHP 5 >= 5.3.0, PECL zip >= 1.9.0)
Add files from a directory by PCRE pattern
bool
renameIndex(int $index, string $new_name)
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
Renames an entry defined by its index
bool
renameName(string $name, string $new_name)
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
Renames an entry defined by its name
bool
setArchiveComment(string $comment)
(PHP 5 >= 5.2.0, PECL zip >= 1.4.0)
Set the comment of a ZIP archive
string|false
getArchiveComment(int $flags = null)
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Returns the Zip archive comment
bool
setCommentIndex(int $index, string $comment)
(PHP 5 >= 5.2.0, PECL zip >= 1.4.0)
Set the comment of an entry defined by its index
bool
setCommentName(string $name, string $comment)
(PHP 5 >= 5.2.0, PECL zip >= 1.4.0)
Set the comment of an entry defined by its name
bool
setCompressionIndex(int $index, int $method, int $compflags = 0)
Set the compression method of an entry defined by its index
bool
setCompressionName(string $name, int $method, int $compflags = 0)
Set the compression method of an entry defined by its name https://secure.php.net/manual/en/ziparchive.setcompressionname.php
bool
setEncryptionIndex(int $index, int $method, string|null $password = null)
Set the encryption method of an entry defined by its index
bool
setEncryptionName(string $name, int $method, string|null $password = null)
Set the encryption method of an entry defined by its name
bool
setPassword(string $password)
(PHP 5 >= 5.6.0, PECL zip >= 1.12.0)
string|false
getCommentIndex(int $index, int $flags = null)
(PHP 5 >= 5.2.0, PECL zip >= 1.4.0)
Returns the comment of an entry using the entry index
string|false
getCommentName(string $name, int $flags = null)
(PHP 5 >= 5.2.0, PECL zip >= 1.4.0)
Returns the comment of an entry using the entry name
bool
deleteIndex(int $index)
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
delete an entry in the archive using its index
bool
deleteName(string $name)
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
delete an entry in the archive using its name
array|false
statName(string $name, int $flags = null)
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
Get the details of an entry defined by its name.
array|false
statIndex(int $index, int $flags = null)
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Get the details of an entry defined by its index.
int|false
locateName(string $name, int $flags = null)
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
Returns the index of the entry in the archive
string|false
getNameIndex(int $index, int $flags = null)
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
Returns the name of an entry using its index
bool
unchangeArchive()
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Revert all global changes done in the archive.
bool
unchangeAll()
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Undo all changes done in the archive
bool
unchangeIndex(int $index)
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Revert all changes done to an entry at the given index
bool
unchangeName(string $name)
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
Revert all changes done to an entry with the given name.
bool
extractTo(string $pathto, string[]|string|null $files = null)
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Extract the archive contents
string|false
getFromName(string $name, int $len = 0, int $flags = null)
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Returns the entry contents using its name
string|false
getFromIndex(int $index, int $len = 0, int $flags = null)
(PHP 5 >= 5.2.0, PECL zip >= 1.3.0)
Returns the entry contents using its index
resource|false
getStream(string $name)
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
Get a file handler to the entry defined by its name (read only).
resource|false
getStreamIndex(int $index, int $flags = 0)
(PHP 8 >= 8.2.0, PECL zip >= 1.20.0)
Get a file handler to the entry defined by its index (read only)
bool
setExternalAttributesName(string $name, int $opsys, int $attr, int $flags = null)
Set the external attributes of an entry defined by its name
bool
getExternalAttributesName(string $name, int $opsys, int $attr, int $flags = null)
Retrieve the external attributes of an entry defined by its name
bool
setExternalAttributesIndex(int $index, int $opsys, int $attr, int $flags = null)
Set the external attributes of an entry defined by its index
bool
getExternalAttributesIndex(int $index, int $opsys, int $attr, int $flags = null)
Retrieve the external attributes of an entry defined by its index
static
isEncryptionMethodSupported($method, $enc = true)
No description
static
isCompressionMethodSupported($method, $enc = true)
No description
bool
registerCancelCallback($callback)
No description
bool
registerProgressCallback($rate, $callback)
No description
bool
setMtimeName($name, $timestamp, $flags = null)
No description
bool
setMtimeIndex($index, $timestamp, $flags = null)
No description
bool
replaceFile($filepath, $index, $start = null, $length = null, $flags = null)
No description
clearError()
No description
bool
setArchiveFlag(int $flag, int $value)
No description
int
getArchiveFlag(int $flag, int $flags = 0)
No description
void
getStreamName(string $name, int $flags = 0)
No description