Download the PHP package lyhiving/zip without Composer
On this page you can find all versions of the php package lyhiving/zip. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package zip
Short Description PhpZip is a php-library for extended work with ZIP-archives. Open, create, update, delete, extract and get info tool. Supports appending to existing ZIP files, WinZip AES encryption, Traditional PKWARE Encryption, BZIP2 compression, external file attributes and ZIP64 extensions. Alternative ZipArchive. It does not require php-zip extension.
License MIT
Homepage https://github.com/lyhiving/php-zip
Informations about the package zip
PhpZip
is a php-library for extended work with ZIP-archives.
=======
74ef59704efd11eb19fe192d1a16772839230f2a
Versions & Dependencies
Version | PHP | Documentation |
---|---|---|
^4.0 (master) | ^7.4|^8.0 | current |
^3.0 | ^5.5|^7.0 | Docs v3.3 |
Versions & Dependencies
Version | PHP | Documentation |
---|---|---|
^4.0 (master) | ^7.4|^8.0 | current |
^3.0 | ^5.5|^7.0 | Docs v3.3 |
Table of contents
- Features
- Requirements
- Installation
- Examples
- Glossary
- Documentation
- Overview of methods of the class
\PhpZip\ZipFile
- Creation/Opening of ZIP-archive
- Reading entries from the archive
- Iterating entries
- Getting information about entries
- Adding entries to the archive
- Deleting entries from the archive
- Working with entries and archive
- Working with passwords
- Undo changes
- Saving a file or output to a browser
- Closing the archive
- Overview of methods of the class
- Running the tests
- Changelog
- Upgrade
- Upgrade version 3 to version 4
- Upgrade version 2 to version 3
Features
- Opening and unzipping zip files.
- Creating ZIP-archives.
- Modifying ZIP archives.
- Pure php (not require extension
php-zip
and class\ZipArchive
). - It supports saving the archive to a file, outputting the archive to the browser, or outputting it as a string without saving it to a file.
- Archival comments and comments of individual entry are supported.
- Get information about each entry in the archive.
- Only the following compression methods are supported:
- No compressed (Stored).
- Deflate compression.
- BZIP2 compression with the extension
php-bz2
.
- Support for
ZIP64
(file size is more than 4 GB or the number of entries in the archive is more than 65535). - Working with passwords
Attention!
For 32-bit systems, the
Traditional PKWARE Encryption (ZipCrypto)
encryption method is not currently supported. Use the encryption methodWinZIP AES Encryption
, whenever possible.- Set the password to read the archive for all entries or only for some.
- Change the password for the archive, including for individual entries.
- Delete the archive password for all or individual entries.
- Set the password and/or the encryption method, both for all, and for individual entries in the archive.
- Set different passwords and encryption methods for different entries.
- Delete the password for all or some entries.
- Support
Traditional PKWARE Encryption (ZipCrypto)
andWinZIP AES Encryption
encryption methods. - Set the encryption method for all or individual entries in the archive.
Requirements
PHP
>= 7.4 orPHP
>= 8.0 (preferably 64-bit).- Optional php-extension
bzip2
for BZIP2 compression. - Optional php-extension
openssl
forWinZip Aes Encryption
support.
Installation
<<<<<<< HEAD
composer require lyhiving/zip
composer require nelexa/zip
74ef59704efd11eb19fe192d1a16772839230f2a
Examples
Other examples can be found in the tests/
folder
Glossary
Zip Entry - file or folder in a ZIP-archive. Each entry in the archive has certain properties, for example: file name, compression method, encryption method, file size before compression, file size after compression, CRC32 and others.
Documentation:
Overview of methods of the class \PhpZip\ZipFile
- ZipFile::__construct - initializes the ZIP archive.
- ZipFile::addAll - adds all entries from an array.
- ZipFile::addDir - adds files to the archive from the directory on the specified path without subdirectories.
- ZipFile::addDirRecursive - adds files to the archive from the directory on the specified path with subdirectories.
- ZipFile::addEmptyDir - add a new directory.
- ZipFile::addFile - adds a file to a ZIP archive from the given path.
- ZipFile::addSplFile - adds a
\SplFileInfo
to a ZIP archive. - ZipFile::addFromFinder - adds files from the
Symfony\Component\Finder\Finder
to a ZIP archive. - ZipFile::addFilesFromIterator - adds files from the iterator of directories.
- ZipFile::addFilesFromGlob - adds files from a directory by glob pattern without subdirectories.
- ZipFile::addFilesFromGlobRecursive - adds files from a directory by glob pattern with subdirectories.
- ZipFile::addFilesFromRegex - adds files from a directory by PCRE pattern without subdirectories.
- ZipFile::addFilesFromRegexRecursive - adds files from a directory by PCRE pattern with subdirectories.
- ZipFile::addFromStream - adds an entry from the stream to the ZIP archive.
- ZipFile::addFromString - adds a file to a ZIP archive using its contents.
- ZipFile::close - close the archive.
- ZipFile::count - returns the number of entries in the archive.
- ZipFile::deleteFromName - deletes an entry in the archive using its name.
- ZipFile::deleteFromGlob - deletes an entries in the archive using glob pattern.
- ZipFile::deleteFromRegex - deletes an entries in the archive using PCRE pattern.
- ZipFile::deleteAll - deletes all entries in the ZIP archive.
- ZipFile::disableEncryption - disable encryption for all entries that are already in the archive.
- ZipFile::disableEncryptionEntry - disable encryption of an entry defined by its name.
- ZipFile::extractTo - extract the archive contents.
- ZipFile::getArchiveComment - returns the Zip archive comment.
- ZipFile::getEntryComment - returns the comment of an entry using the entry name.
- ZipFile::getEntryContent - returns the entry contents using its name.
- ZipFile::getListFiles - returns list of archive files.
- ZipFile::hasEntry - checks if there is an entry in the archive.
- ZipFile::isDirectory - checks that the entry in the archive is a directory.
- ZipFile::matcher - selecting entries in the archive to perform operations on them.
- ZipFile::openFile - opens a zip-archive from a file.
- ZipFile::openFromString - opens a zip-archive from a string.
- ZipFile::openFromStream - opens a zip-archive from the stream.
- ZipFile::outputAsAttachment - outputs a ZIP-archive to the browser.
- ZipFile::outputAsPsr7Response - outputs a ZIP-archive as PSR-7 Response.
- ZipFile::outputAsSymfonyResponse - outputs a ZIP-archive as Symfony Response.
- ZipFile::outputAsString - outputs a ZIP-archive as string.
- ZipFile::rename - renames an entry defined by its name.
- ZipFile::rewrite - save changes and re-open the changed archive.
- ZipFile::saveAsFile - saves the archive to a file.
- ZipFile::saveAsStream - writes the archive to the stream.
- ZipFile::setArchiveComment - set the comment of a ZIP archive.
- ZipFile::setCompressionLevel - set the compression level for all files in the archive.
- ZipFile::setCompressionLevelEntry - sets the compression level for the entry by its name.
- ZipFile::setCompressionMethodEntry - sets the compression method for the entry by its name.
- ZipFile::setEntryComment - set the comment of an entry defined by its name.
- ZipFile::setReadPassword - set the password for the open archive.
- ZipFile::setReadPasswordEntry - sets a password for reading of an entry defined by its name.
- ZipFile::setPassword - sets a new password for all files in the archive.
- ZipFile::setPasswordEntry - sets a new password of an entry defined by its name.
- ZipFile::unchangeAll - undo all changes done in the archive.
- ZipFile::unchangeArchiveComment - undo changes to the archive comment.
- ZipFile::unchangeEntry - undo changes of an entry defined by its name.
Creation/Opening of ZIP-archive
ZipFile::__construct**
Initializes the ZIP archive
ZipFile::openFile
Opens a zip-archive from a file.
ZipFile::openFromString
Opens a zip-archive from a string.
ZipFile::openFromStream
Opens a zip-archive from the stream.
Reading entries from the archive
ZipFile::count
Returns the number of entries in the archive.
ZipFile::getListFiles
Returns list of archive files.
ZipFile::getEntryContent
Returns the entry contents using its name.
ZipFile::hasEntry
Checks if there is an entry in the archive.
ZipFile::isDirectory
Checks that the entry in the archive is a directory.
ZipFile::extractTo
Extract the archive contents. The directory must exist.
Extract some files to the directory. The directory must exist.
Iterating entries
ZipFile
is an iterator.
Can iterate all the entries in the foreach
loop.
Can iterate through the Iterator
.
Getting information about entries
ZipFile::getArchiveComment
Returns the Zip archive comment.
ZipFile::getEntryComment
Returns the comment of an entry using the entry name.
Adding entries to the archive
All methods of adding entries to a ZIP archive allow you to specify a method for compressing content.
The following methods of compression are available:
\PhpZip\Constants\ZipCompressionMethod::STORED
- no compression\PhpZip\Constants\ZipCompressionMethod::DEFLATED
- Deflate compression\PhpZip\Constants\ZipCompressionMethod::BZIP2
- Bzip2 compression with the extensionext-bz2
ZipFile::addFile
Adds a file to a ZIP archive from the given path.
ZipFile::addSplFile
Adds a \SplFileInfo
to a ZIP archive.
ZipFile::addFromFinder
Adds files from the Symfony\Component\Finder\Finder
to a ZIP archive.
ZipFile::addFromString
Adds a file to a ZIP archive using its contents.
ZipFile::addFromStream
Adds an entry from the stream to the ZIP archive.
ZipFile::addEmptyDir
Add a new directory.
ZipFile::addAll
Adds all entries from an array.
ZipFile::addDir
Adds files to the archive from the directory on the specified path without subdirectories.
ZipFile::addDirRecursive
Adds files to the archive from the directory on the specified path with subdirectories.
ZipFile::addFilesFromIterator
Adds files from the iterator of directories.
Example with some files ignoring:
ZipFile::addFilesFromGlob
Adds files from a directory by glob pattern without subdirectories.
ZipFile::addFilesFromGlobRecursive
Adds files from a directory by glob pattern with subdirectories.
ZipFile::addFilesFromRegex
Adds files from a directory by PCRE pattern without subdirectories.
ZipFile::addFilesFromRegexRecursive
Adds files from a directory by PCRE pattern with subdirectories.
Deleting entries from the archive
ZipFile::deleteFromName
Deletes an entry in the archive using its name.
ZipFile::deleteFromGlob
Deletes a entries in the archive using glob pattern.
ZipFile::deleteFromRegex
Deletes a entries in the archive using PCRE pattern.
ZipFile::deleteAll
Deletes all entries in the ZIP archive.
Working with entries and archive
ZipFile::rename
Renames an entry defined by its name.
ZipFile::setCompressionLevel
Set the compression level for all files in the archive.
Note that this method does not apply to entries that are added after this method is run.
By default, the compression level is 5 (\PhpZip\Constants\ZipCompressionLevel::NORMAL
) or the compression level specified in the archive for Deflate compression.
The values range from 1 (\PhpZip\Constants\ZipCompressionLevel::SUPER_FAST
) to 9 (\PhpZip\Constants\ZipCompressionLevel::MAXIMUM
) are supported. The higher the number, the better and longer the compression.
ZipFile::setCompressionLevelEntry
Sets the compression level for the entry by its name.
The values range from 1 (\PhpZip\Constants\ZipCompressionLevel::SUPER_FAST
) to 9 (\PhpZip\Constants\ZipCompressionLevel::MAXIMUM
) are supported. The higher the number, the better and longer the compression.
ZipFile::setCompressionMethodEntry
Sets the compression method for the entry by its name.
The following compression methods are available:
\PhpZip\Constants\ZipCompressionMethod::STORED
- No compression\PhpZip\Constants\ZipCompressionMethod::DEFLATED
- Deflate compression\PhpZip\Constants\ZipCompressionMethod::BZIP2
- Bzip2 compression with the extensionext-bz2
ZipFile::setArchiveComment
Set the comment of a ZIP archive.
ZipFile::setEntryComment
Set the comment of an entry defined by its name.
ZipFile::matcher
Selecting entries in the archive to perform operations on them.
Selecting files from the archive one at a time:
Select multiple files in the archive:
Selecting files by regular expression:
Select all files in the archive:
count() - gets the number of selected entries:
getMatches() - returns a list of selected entries:
invoke() - invoke a callable function on selected entries:
Functions for working on the selected entries:
Working with passwords
Implemented support for encryption methods:
\PhpZip\Constants\ZipEncryptionMethod::PKWARE
- Traditional PKWARE encryption (legacy)\PhpZip\Constants\ZipEncryptionMethod::WINZIP_AES_256
- WinZip AES encryption 256 bit (recommended)\PhpZip\Constants\ZipEncryptionMethod::WINZIP_AES_192
- WinZip AES encryption 192 bit\PhpZip\Constants\ZipEncryptionMethod::WINZIP_AES_128
- WinZip AES encryption 128 bit
ZipFile::setReadPassword
Set the password for the open archive.
Setting a password is not required for adding new entries or deleting existing ones, but if you want to extract the content or change the method / compression level, the encryption method, or change the password, in this case the password must be specified.
ZipFile::setReadPasswordEntry
Gets a password for reading of an entry defined by its name.
ZipFile::setPassword
Sets a new password for all files in the archive.
Note that this method does not apply to entries that are added after this method is run.
You can set the encryption method:
ZipFile::setPasswordEntry
Sets a new password of an entry defined by its name.
You can set the encryption method:
ZipFile::disableEncryption
Disable encryption for all entries that are already in the archive.
Note that this method does not apply to entries that are added after this method is run.
ZipFile::disableEncryptionEntry
Disable encryption of an entry defined by its name.
Undo changes
ZipFile::unchangeAll
Undo all changes done in the archive.
ZipFile::unchangeArchiveComment
Undo changes to the archive comment.
ZipFile::unchangeEntry
Undo changes of an entry defined by its name.
Saving a file or output to a browser
ZipFile::saveAsFile
Saves the archive to a file.
ZipFile::saveAsStream
Writes the archive to the stream.
ZipFile::outputAsString
Outputs a ZIP-archive as string.
ZipFile::outputAsAttachment
Outputs a ZIP-archive to the browser.
You can set the Mime-Type:
ZipFile::outputAsPsr7Response
Outputs a ZIP-archive as PSR-7 Response.
The output method can be used in any PSR-7 compatible framework.
You can set the Mime-Type:
ZipFile::outputAsSymfonyResponse
Outputs a ZIP-archive as Symfony Response.
The output method can be used in Symfony framework.
You can set the Mime-Type:
Example use in Symfony Controller:
ZipFile::rewrite
Save changes and re-open the changed archive.
Closing the archive
ZipFile::close
Close the archive.
Running the tests
Install the dependencies for the development:
Run the tests:
Changelog
Changes are documented in the releases page.
Upgrade
Upgrade version 3 to version 4
Update the major version in the file composer.json
to ^4.0
.
Then install updates using Composer
:
Update your code to work with the new version: BC
- removed deprecated classes and methods.
- removed
zipalign
functional. This functionality will be placed in a separate packagenelexa/apkfile
.
Upgrade version 2 to version 3
Update the major version in the file composer.json
to ^3.0
.
Then install updates using Composer
:
Update your code to work with the new version:
- Class
ZipOutputFile
merged toZipFile
and removed.new \PhpZip\ZipOutputFile()
tonew \PhpZip\ZipFile()
- Static initialization methods are now not static.
\PhpZip\ZipFile::openFromFile($filename);
to(new \PhpZip\ZipFile())->openFile($filename);
\PhpZip\ZipOutputFile::openFromFile($filename);
to(new \PhpZip\ZipFile())->openFile($filename);
\PhpZip\ZipFile::openFromString($contents);
to(new \PhpZip\ZipFile())->openFromString($contents);
\PhpZip\ZipFile::openFromStream($stream);
to(new \PhpZip\ZipFile())->openFromStream($stream);
\PhpZip\ZipOutputFile::create()
tonew \PhpZip\ZipFile()
\PhpZip\ZipOutputFile::openFromZipFile(\PhpZip\ZipFile $zipFile)
>(new \PhpZip\ZipFile())->openFile($filename);
- Rename methods:
addFromFile
toaddFile
setLevel
tosetCompressionLevel
ZipFile::setPassword
toZipFile::withReadPassword
ZipOutputFile::setPassword
toZipFile::withNewPassword
ZipOutputFile::disableEncryptionAllEntries
toZipFile::withoutPassword
ZipOutputFile::setComment
toZipFile::setArchiveComment
ZipFile::getComment
toZipFile::getArchiveComment
- Changed signature for methods
addDir
,addFilesFromGlob
,addFilesFromRegex
. - Remove methods:
getLevel
setCompressionMethod
setEntryPassword
All versions of zip with dependencies
ext-zlib Version *
psr/http-message Version *
symfony/finder Version *