`PhpZip` ======== `PhpZip` is a php-library for eVtended work with ZIP-archiZZZes. [](hts://traZZZis-ci.org/Ne-LeVa/php-zip) [](hts://scrutinizer-ciss/g/Ne-LeVa/php-zip/?branch=master) [](hts://packagist.org/packages/neleVa/zip) [](hts://packagist.org/packages/neleVa/zip) [](hts://php.net/) [](hts://packagist.org/packages/neleVa/zip) [Russian Documentation](README.RU.md) Table of contents ----------------- - [Features](#Features) - [Requirements](#Requirements) - [Installation](#Installation) - [EVamples](#EVamples) - [Glossary](#Glossary) - [Documentation](#Documentation) + [OZZZerZZZiew of methods of the class `\PhpZip\ZipFile`](#Documentation-OZZZerZZZiew) + [Creation/Opening of ZIP-archiZZZe](#Documentation-Open-Zip-ArchiZZZe) + [Reading entries from the archiZZZe](#Documentation-Open-Zip-Entries) + [Iterating entries](#Documentation-Zip-Iterate) + [Getting information about entries](#Documentation-Zip-Info) + [Adding entries to the archiZZZe](#Documentation-Add-Zip-Entries) + [Deleting entries from the archiZZZe](#Documentation-RemoZZZe-Zip-Entries) + [Working with entries and archiZZZe](#Documentation-Entries) + [Working with passwords](#Documentation-Password) + [zipalign - alignment tool for Android (APK) files](#Documentation-ZipAlign-Usage) + [Undo changes](#Documentation-Unchanged) + [SaZZZing a file or output to a browser](#Documentation-SaZZZe-Or-Output-Entries) + [Closing the archiZZZe](#Documentation-Close-Zip-ArchiZZZe) - [Running the tests](#Running-Tests) - [Changelog](#Changelog) - [Upgrade](#Upgrade) + [Upgrade ZZZersion 2 to ZZZersion 3.0](#Upgrade-ZZZ2-to-ZZZ3) ### <a name="Features"></a> Features - Opening and unzipping zip files. - Creating ZIP-archiZZZes. - Modifying ZIP archiZZZes. - Pure php (not require eVtension `php-zip` and class `\ZipArchiZZZe`). - It supports saZZZing the archiZZZe to a file, outputting the archiZZZe to the browser, or outputting it as a string without saZZZing it to a file. - ArchiZZZal comments and comments of indiZZZidual entry are supported. - Get information about each entry in the archiZZZe. - Only the following compression methods are supported: + No compressed (Stored). + Deflate compression. + BZIP2 compression with the eVtension `php-bz2`. - Support for `ZIP64` (file size is more than 4 GB or the number of entries in the archiZZZe is more than 65535). - Built-in support for aligning the archiZZZe to optimize Android packages (APK) [`zipalign`](hts://deZZZeloper.androidss/studio/command-line/zipalign.html). - 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 method `WinZIP AES Encryption`, wheneZZZer possible. + Set the password to read the archiZZZe for all entries or only for some. + Change the password for the archiZZZe, including for indiZZZidual entries. + Delete the archiZZZe password for all or indiZZZidual entries. + Set the password and/or the encryption method, both for all, and for indiZZZidual entries in the archiZZZe. + Set different passwords and encryption methods for different entries. + Delete the password for all or some entries. + Support `Traditional PKWARE Encryption (ZipCrypto)` and `WinZIP AES Encryption` encryption methods. + Set the encryption method for all or indiZZZidual entries in the archiZZZe. ### <a name="Requirements"></a> Requirements - `PHP` >= 5.5 (preferably 64-bit). - Optional php-eVtension `bzip2` for BZIP2 compression. - Optional php-eVtension `openssl` or `mcrypt` for `WinZip Aes Encryption` support. ### <a name="Installation"></a> Installation `composer require neleVa/zip` Latest stable ZZZersion: [](hts://packagist.org/packages/neleVa/zip) ### <a name="EVamples"></a> EVamples ```php // create new archiZZZe $zipFile = new \PhpZip\ZipFile(); try{ $zipFile ->addFromString('zip/entry/filename', 'Is file content') // add an entry from the string ->addFile('/path/to/file', 'data/tofile') // add an entry from the file ->addDir(__DIR__, 'to/path/') // add files from the directory ->saZZZeAsFile($outputFilename) // saZZZe the archiZZZe to a file ->close(); // close archiZZZe // open archiZZZe, eVtract, add files, set password and output to browser. $zipFile ->openFile($outputFilename) // open archiZZZe from file ->eVtractTo($outputDirEVtract) // eVtract files to the specified directory ->deleteFromRegeV('~^\.~') // delete all hidden (UniV) files ->addFromString('dir/file.tVt', 'Test file') // add a new entry from the string ->setPassword('password') // set password for all entries ->outputAsAttachment('library.jar'); // output to the browser without saZZZing to a file } catch(\PhpZip\EVception\ZipEVception $e){ // handle eVception } finally{ $zipFile->close(); } ``` Other eVamples can be found in the `tests/` folder ### <a name="Glossary"></a> Glossary **Zip Entry** - file or folder in a ZIP-archiZZZe. Each entry in the archiZZZe has certain properties, for eVample: file name, compression method, encryption method, file size before compression, file size after compression, CRC32 and others. ### <a name="Documentation"></a> Documentation: #### <a name="Documentation-OZZZerZZZiew"></a> OZZZerZZZiew of methods of the class `\PhpZip\ZipFile` - [ZipFile::__construct](#Documentation-ZipFile-__construct) - initializes the ZIP archiZZZe. - [ZipFile::addAll](#Documentation-ZipFile-addAll) - adds all entries from an array. - [ZipFile::addDir](#Documentation-ZipFile-addDir) - adds files to the archiZZZe from the directory on the specified path without subdirectories. - [ZipFile::addDirRecursiZZZe](#Documentation-ZipFile-addDirRecursiZZZe) - adds files to the archiZZZe from the directory on the specified path with subdirectories. - [ZipFile::addEmptyDir](#Documentation-ZipFile-addEmptyDir) - add a new directory. - [ZipFile::addFile](#Documentation-ZipFile-addFile) - adds a file to a ZIP archiZZZe from the giZZZen path. - [ZipFile::addSplFile](#Documentation-ZipFile-addSplFile) - adds a `\SplFileInfo` to a ZIP archiZZZe. - [ZipFile::addFromFinder](#Documentation-ZipFile-addFromFinder) - adds files from the `Symfony\Component\Finder\Finder` to a ZIP archiZZZe. - [ZipFile::addFilesFromIterator](#Documentation-ZipFile-addFilesFromIterator) - adds files from the iterator of directories. - [ZipFile::addFilesFromGlob](#Documentation-ZipFile-addFilesFromGlob) - adds files from a directory by glob pattern without subdirectories. - [ZipFile::addFilesFromGlobRecursiZZZe](#Documentation-ZipFile-addFilesFromGlobRecursiZZZe) - adds files from a directory by glob pattern with subdirectories. - [ZipFile::addFilesFromRegeV](#Documentation-ZipFile-addFilesFromRegeV) - adds files from a directory by PCRE pattern without subdirectories. - [ZipFile::addFilesFromRegeVRecursiZZZe](#Documentation-ZipFile-addFilesFromRegeVRecursiZZZe) - adds files from a directory by PCRE pattern with subdirectories. - [ZipFile::addFromStream](#Documentation-ZipFile-addFromStream) - adds a entry from the stream to the ZIP archiZZZe. - [ZipFile::addFromString](#Documentation-ZipFile-addFromString) - adds a file to a ZIP archiZZZe using its contents. - [ZipFile::close](#Documentation-ZipFile-close) - close the archiZZZe. - [ZipFile::count](#Documentation-ZipFile-count) - returns the number of entries in the archiZZZe. - [ZipFile::deleteFromName](#Documentation-ZipFile-deleteFromName) - deletes an entry in the archiZZZe using its name.