Download the PHP package radionovel/php-zip without Composer
On this page you can find all versions of the php package radionovel/php-zip. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download radionovel/php-zip
More information about radionovel/php-zip
Files in radionovel/php-zip
Package php-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, ZipAlign tool, BZIP2 compression, external file attributes and ZIP64 extensions. Alternative ZipArchive. It does not require php-zip extension.
License MIT
Homepage https://github.com/Ne-Lexa/php-zip
Informations about the package php-zip
PhpZip
PhpZip
is a php-library for extended work with ZIP-archives.
Russian Documentation
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
- zipalign - alignment tool for Android (APK) files
- 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 2 to version 3.0
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). - Built-in support for aligning the archive to optimize Android packages (APK)
zipalign
. - Working with passwords for PHP 5.5
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
>= 5.5 (preferably 64-bit).- Optional php-extension
bzip2
for BZIP2 compression. - Optional php-extension
openssl
ormcrypt
forWinZip Aes Encryption
support.
Installation
composer require nelexa/zip
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 a 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 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.
- 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::getAllInfo - returns detailed information about all entries in the archive.
- 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::getEntryInfo - returns detailed information about the entry in the archive.
- 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::outputAsResponse - outputs a ZIP-archive as PSR-7 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::withNewPassword- is an deprecated method, use the ZipFile::setPassword method.- 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::setZipAlign - sets the alignment of the archive to optimize APK files (Android packages).
- 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.
ZipFile::withoutPassword- is an deprecated method, use the ZipFile::disableEncryption method.ZipFile::withReadPassword- is an deprecated method, use the ZipFile::setReadPassword method.
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.
ZipFile::getEntryInfo - returns detailed information about the entry in the archive
ZipFile::getAllInfo - returns detailed information about all entries in the archive.
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.
https://symfony.com/doc/current/components/finder.html
ZipFile::addFromString - adds a file to a ZIP archive using its contents.
ZipFile::addFromStream - adds a 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.
zipalign
ZipFile::setZipAlign - sets the alignment of the archive to optimize APK files (Android packages).
This method adds padding to unencrypted and not compressed entries, to optimize memory consumption in the Android system. It is recommended to use for APK
files. The file may grow slightly.
This method is an alternative to executing the zipalign -f -v 4 filename.zip
.
More details can be found on the link.
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::outputAsResponse - 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::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 2 to version 3.0
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 php-zip with dependencies
ext-zlib Version *
psr/http-message Version ^1.0
paragonie/random_compat Version *
symfony/finder Version ^3.0|^4.0|^5.0