The ZipArchive class

Introduction

A file archive, compressed with Zip.

Class synopsis

ZipArchive
implements Countable
/* Constants */
public const int ZipArchive::CREATE;
public const int ZipArchive::EXCL;
public const int ZipArchive::CHECKCONS;
public const int ZipArchive::OVERWRITE;
public const int ZipArchive::RDONLY;
public const int ZipArchive::FL_NOCASE;
public const int ZipArchive::FL_NODIR;
public const int ZipArchive::FL_COMPRESSED;
public const int ZipArchive::FL_UNCHANGED;
public const int ZipArchive::FL_RECOMPRESS;
public const int ZipArchive::FL_ENCRYPTED;
public const int ZipArchive::FL_OVERWRITE;
public const int ZipArchive::FL_LOCAL;
public const int ZipArchive::FL_CENTRAL;
public const int ZipArchive::FL_ENC_GUESS;
public const int ZipArchive::FL_ENC_RAW;
public const int ZipArchive::FL_ENC_STRICT;
public const int ZipArchive::FL_ENC_UTF_8;
public const int ZipArchive::FL_ENC_CP437;
public const int ZipArchive::FL_OPEN_FILE_NOW;
public const int ZipArchive::CM_DEFAULT;
public const int ZipArchive::CM_STORE;
public const int ZipArchive::CM_SHRINK;
public const int ZipArchive::CM_REDUCE_1;
public const int ZipArchive::CM_REDUCE_2;
public const int ZipArchive::CM_REDUCE_3;
public const int ZipArchive::CM_REDUCE_4;
public const int ZipArchive::CM_IMPLODE;
public const int ZipArchive::CM_DEFLATE;
public const int ZipArchive::CM_DEFLATE64;
public const int ZipArchive::CM_PKWARE_IMPLODE;
public const int ZipArchive::CM_BZIP2;
public const int ZipArchive::CM_LZMA;
public const int ZipArchive::CM_LZMA2;
public const int ZipArchive::CM_ZSTD;
public const int ZipArchive::CM_XZ;
public const int ZipArchive::CM_TERSE;
public const int ZipArchive::CM_LZ77;
public const int ZipArchive::CM_WAVPACK;
public const int ZipArchive::CM_PPMD;
public const int ZipArchive::ER_OK;
public const int ZipArchive::ER_MULTIDISK;
public const int ZipArchive::ER_RENAME;
public const int ZipArchive::ER_CLOSE;
public const int ZipArchive::ER_SEEK;
public const int ZipArchive::ER_READ;
public const int ZipArchive::ER_WRITE;
public const int ZipArchive::ER_CRC;
public const int ZipArchive::ER_ZIPCLOSED;
public const int ZipArchive::ER_NOENT;
public const int ZipArchive::ER_EXISTS;
public const int ZipArchive::ER_OPEN;
public const int ZipArchive::ER_TMPOPEN;
public const int ZipArchive::ER_ZLIB;
public const int ZipArchive::ER_MEMORY;
public const int ZipArchive::ER_CHANGED;
public const int ZipArchive::ER_COMPNOTSUPP;
public const int ZipArchive::ER_EOF;
public const int ZipArchive::ER_INVAL;
public const int ZipArchive::ER_NOZIP;
public const int ZipArchive::ER_INTERNAL;
public const int ZipArchive::ER_INCONS;
public const int ZipArchive::ER_REMOVE;
public const int ZipArchive::ER_DELETED;
public const int ZipArchive::ER_ENCRNOTSUPP;
public const int ZipArchive::ER_RDONLY;
public const int ZipArchive::ER_NOPASSWD;
public const int ZipArchive::ER_WRONGPASSWD;
public const int ZipArchive::ER_OPNOTSUPP;
public const int ZipArchive::ER_INUSE;
public const int ZipArchive::ER_TELL;
public const int ZipArchive::ER_COMPRESSED_DATA;
public const int ZipArchive::ER_CANCELLED;
public const int ZipArchive::ER_DATA_LENGTH;
public const int ZipArchive::ER_NOT_ALLOWED;
public const int ZipArchive::AFL_RDONLY;
public const int ZipArchive::AFL_IS_TORRENTZIP;
public const int ZipArchive::AFL_WANT_TORRENTZIP;
public const int ZipArchive::AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE;
public const int ZipArchive::OPSYS_DOS;
public const int ZipArchive::OPSYS_AMIGA;
public const int ZipArchive::OPSYS_OPENVMS;
public const int ZipArchive::OPSYS_UNIX;
public const int ZipArchive::OPSYS_VM_CMS;
public const int ZipArchive::OPSYS_ATARI_ST;
public const int ZipArchive::OPSYS_OS_2;
public const int ZipArchive::OPSYS_MACINTOSH;
public const int ZipArchive::OPSYS_Z_SYSTEM;
public const int ZipArchive::OPSYS_CPM;
public const int ZipArchive::OPSYS_WINDOWS_NTFS;
public const int ZipArchive::OPSYS_MVS;
public const int ZipArchive::OPSYS_VSE;
public const int ZipArchive::OPSYS_ACORN_RISC;
public const int ZipArchive::OPSYS_VFAT;
public const int ZipArchive::OPSYS_ALTERNATE_MVS;
public const int ZipArchive::OPSYS_BEOS;
public const int ZipArchive::OPSYS_TANDEM;
public const int ZipArchive::OPSYS_OS_400;
public const int ZipArchive::OPSYS_OS_X;
public const int ZipArchive::OPSYS_DEFAULT;
public const int ZipArchive::EM_NONE;
public const int ZipArchive::EM_TRAD_PKWARE;
public const int ZipArchive::EM_AES_128;
public const int ZipArchive::EM_AES_192;
public const int ZipArchive::EM_AES_256;
public const int ZipArchive::EM_UNKNOWN;
public const string ZipArchive::LIBZIP_VERSION;
public const int ZipArchive::LENGTH_TO_END;
public const int ZipArchive::LENGTH_UNCHECKED;
/* Properties */
public readonly int $lastId;
public readonly int $status;
public readonly int $statusSys;
public readonly int $numFiles;
public readonly string $filename;
public readonly string $comment;
/* Methods */
public bool addEmptyDir(string $dirname, int $flags = 0)
public bool addFile(
    string $filepath,
    string $entryname = "",
    int $start = 0,
    int $length = ZipArchive::LENGTH_TO_END,
    int $flags = ZipArchive::FL_OVERWRITE
)
public bool addFromString(string $name, string $content, int $flags = ZipArchive::FL_OVERWRITE)
public arrayfalse addGlob(string $pattern, int $flags = 0, array $options = [])
public arrayfalse addPattern(string $pattern, string $path = ".", array $options = [])
public void clearError()
public bool close()
public int count()
public bool deleteIndex(int $index)
public bool deleteName(string $name)
public bool extractTo(string $pathto, arraystringnull $files = null)
public stringfalse getArchiveComment(int $flags = 0)
public int getArchiveFlag(int $flag, int $flags = 0)
public stringfalse getCommentIndex(int $index, int $flags = 0)
public stringfalse getCommentName(string $name, int $flags = 0)
public bool getExternalAttributesIndex(
    int $index,
    int &$opsys,
    int &$attr,
    int $flags = 0
)
public bool getExternalAttributesName(
    string $name,
    int &$opsys,
    int &$attr,
    int $flags = 0
)
public stringfalse getFromIndex(int $index, int $len = 0, int $flags = 0)
public stringfalse getFromName(string $name, int $len = 0, int $flags = 0)
public stringfalse getNameIndex(int $index, int $flags = 0)
public string getStatusString()
public resourcefalse getStream(string $name)
public resourcefalse getStreamIndex(int $index, int $flags = 0)
public resourcefalse getStreamName(string $name, int $flags = 0)
public static bool isCompressionMethodSupported(int $method, bool $enc = true)
public static bool isEncryptionMethodSupported(int $method, bool $enc = true)
public intfalse locateName(string $name, int $flags = 0)
public boolint open(string $filename, int $flags = 0)
public bool registerCancelCallback(callable $callback)
public bool registerProgressCallback(float $rate, callable $callback)
public bool renameIndex(int $index, string $new_name)
public bool renameName(string $name, string $new_name)
public bool replaceFile(
    string $filepath,
    int $index,
    int $start = 0,
    int $length = ZipArchive::LENGTH_TO_END,
    int $flags = 0
)
public bool setArchiveComment(string $comment)
public bool setArchiveFlag(int $flag, int $value)
public bool setCommentIndex(int $index, string $comment)
public bool setCommentName(string $name, string $comment)
public bool setCompressionIndex(int $index, int $method, int $compflags = 0)
public bool setCompressionName(string $name, int $method, int $compflags = 0)
public bool setEncryptionIndex(int $index, int $method, #[\SensitiveParameter]stringnull $password = null)
public bool setEncryptionName(string $name, int $method, #[\SensitiveParameter]stringnull $password = null)
public bool setExternalAttributesIndex(
    int $index,
    int $opsys,
    int $attr,
    int $flags = 0
)
public bool setExternalAttributesName(
    string $name,
    int $opsys,
    int $attr,
    int $flags = 0
)
public bool setMtimeIndex(int $index, int $timestamp, int $flags = 0)
public bool setMtimeName(string $name, int $timestamp, int $flags = 0)
public bool setPassword(#[\SensitiveParameter]string $password)
public arrayfalse statIndex(int $index, int $flags = 0)
public arrayfalse statName(string $name, int $flags = 0)
public bool unchangeAll()
public bool unchangeArchive()
public bool unchangeIndex(int $index)
public bool unchangeName(string $name)

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