PHP Zip Merge: Merge and stream multiple ZIP files

Recommend this page to a friend!
  Info   Example   View files (24)   Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 295 All time: 7,342 This week: 307
Version License PHP version Categories
php-zip-merge 1.0.3GNU Lesser Genera...5.3PHP 5, Files and Folders, Compression
Description Author

This class can merge and stream multiple ZIP files into a single ZIP file without compressing again the files contained in the archives.

It can create a new ZIP archive including files of one or more other ZIP files.

The files of each merged ZIP archive can be inserted in a given directory.

The resulting merged ZIP archive may be served for download or stored in a new file.

Innovation Award
PHP Programming Innovation award nominee
August 2014
Number 4

Prize: One copy of the Zend Studio
Some applications need to combine the contents of multiple ZIP files. Usually they uncompress the input ZIP files contents and recompress it to build the final ZIP archive.

This class provides a more efficient solution that does not require uncompressing the input ZIP files.

Manuel Lemos
Picture of Asbjorn Grandt
Name: Asbjorn Grandt <contact>
Classes: 10 packages by
Country: Denmark Denmark
Age: 48
All time rank: 1771 in Denmark Denmark
Week rank: 84 1 in Denmark Denmark
Innovation award
Innovation award
Nominee: 4x



Combine and stream the contents of multiple existing Zip files, as a single file, without recompressing the data within.

This is useful if you have often used static content that needs to be collected and sent to the client. With this you can pre-compress these packages, and assemble them on the fly, saving CPU cycles by not having to do the compression every time the files are requested.

The contents of each Zip file added, can even be placed in separate sub folders.



Add this requirement to your composer.json file:

   "grandt/phpzipmerge": ">=1.0.4"


If you already have Composer installed, skip this part.

Packagist, the main composer repository has a neat and very short guide.

Or you can look at the guide at the Composer site.

The easiest for first time users, is to have the composer installed in the same directory as your composer.json file, though there are better options.

Run this from the command line:

php -r "readfile('');" | php

This will check your PHP installation, and download the composer.phar, which is the composer binary. This file is not needed on the server though.

Once composer is installed you can create the composer.json file to import this package.

    "require": {
        "grandt/phpzipmerge": ">=1.0.4",
        "php": ">=5.3.0"

Followed by telling Composer to install the dependencies.

php composer.phar install

this will download and place all dependencies defined in your composer.json file in the vendor directory.

Finally, you include the autoload.php file in the new vendor directory.

    require 'vendor/autoload.php';
File Role Description
src (1 directory)
tests (2 files)
composer.json Data Composer.json file Data Readme
REVISION.TXT Data Revision history

  Files  /  src  
File Role Description
ZipMerge (1 directory)

  Files  /  src  /  ZipMerge  
File Role Description
Zip (5 directories)

  Files  /  src  /  ZipMerge  /  Zip  
File Role Description
Core (3 files, 2 directories)
Exception (4 files)
File (1 file)
Listener (1 file)
Stream (1 file)

  Files  /  src  /  ZipMerge  /  Zip  /  Core  
File Role Description
ExtraField (6 files)
Header (3 files)
   AbstractException.php Class Class file
   AbstractZipWriter.php Class Class file
   ZipUtils.php Class Class file

  Files  /  src  /  ZipMerge  /  Zip  /  Core  /  ExtraField  
File Role Description
   AbstractExtraField.php Class Class file
   AbstractUnicodeExtraField.php Class Class file
   ExtendedTimeStampExtraField.php Class Class file
   GenericExtraField.php Class Class file
   UnicodeCommentExtraField.php Class Class file
   UnicodePathExtraField.php Class Class file

  Files  /  src  /  ZipMerge  /  Zip  /  Core  /  Header  
File Role Description
   AbstractZipHeader.php Class Class file
   EndOfCentralDirectory.php Class Class file
   ZipFileEntry.php Class Class file

  Files  /  src  /  ZipMerge  /  Zip  /  Exception  
File Role Description
   BufferNotEmpty.php Class Class file
   HeaderPositionError.php Class Class file
   HeadersSent.php Class Class file
   IncompatiblePhpVersion.php Class Class file

  Files  /  src  /  ZipMerge  /  Zip  /  File  
File Role Description
   ZipMergeToFile.php Class Stepping to version 1.0.2 Added class to write to file ZipMerge always streams to the client, the new ZipMergeToFile will write directly to a file instead, phpclasses accidentally said the package could do this... :P

  Files  /  src  /  ZipMerge  /  Zip  /  Listener  
File Role Description
   ZipArchiveListener.php Class Class file

  Files  /  src  /  ZipMerge  /  Zip  /  Stream  
File Role Description
   ZipMerge.php Class Main Class file

  Files  /  tests  
File Role Description
   MergeZip.Example1.php Example Example showing the use of the ZipMerge Class
   MergeZip.File.Example1.php Example Stepping to version 1.0.2 Added class to write to file ZipMerge always streams to the client, the new ZipMergeToFile will write directly to a file instead, phpclasses accidentally said the package could do this... :P 26KB
php-zip-merge-2015-08-19.tar.gz 15KB
Install with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Relative Path .zip .tar.gz Clean and manage paths before adding them to the zip file Required
Bin String .zip .tar.gz Work around cases where mbstring.func_overload is enabled Required
 Version Control Reuses Unique User Downloads Download Rankings  
This week:0
All time:7,342
This week:307

For more information send a message to info at phpclasses dot org.