PHP Classes

PHP Zip Merge: Merge and stream multiple ZIP files

Recommend this page to a friend!
  Info   View files Example   View files View files (24)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 321 All time: 7,215 This week: 164Up
Version License PHP version Categories
php-zip-merge 1.0.12GNU Lesser Genera...5.3PHP 5, Files and Folders, Compression
Description 

Authors

A. Grandt
Greg Kappatos


Contributor

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: 52
All time rank: 1711 in Denmark Denmark
Week rank: 91 Up1 in Denmark Denmark Equal
Innovation award
Innovation award
Nominee: 4x

Example

<?php
error_reporting
(E_ALL | E_STRICT);
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 1);

include
"../vendor/autoload.php";

$outFile = "ZipMerge.test1.zip";

$zipMerge = new \ZipMerge\Zip\Stream\ZipMerge($outFile);
$zipMerge->appendZip("../testData/500k.zip", "TrueCryptRandomFile/");
$zipMerge->appendZip("../testData/test.zip", "A-book");
/*
$handle = fopen("ZipStreamExample1.zip", 'r');
$zipMerge->appendZip($handle, "ZipStreamExample1.zip");
fclose($handle);
*/
$zipMerge->finalize();


Details

ZipMerge

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.

Installation

Import

Add this requirement to your composer.json file:

   "grandt/phpzipmerge": ">=1.0.4"

Composer

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('https://getcomposer.org/installer');" | 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.

<?php
    require 'vendor/autoload.php';
    .
    .
    .

  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Files folder imagetests (2 files)
Accessible without login Plain text file composer.json Data Composer.json file
Accessible without login Plain text file README.md Data Readme
Accessible without login Plain text file REVISION.TXT Data Revision history

  Files folder image Files  /  src  
File Role Description
Files folder imageZipMerge (1 directory)

  Files folder image Files  /  src  /  ZipMerge  
File Role Description
Files folder imageZip (5 directories)

  Files folder image Files  /  src  /  ZipMerge  /  Zip  
File Role Description
Files folder imageCore (3 files, 2 directories)
Files folder imageException (4 files)
Files folder imageFile (1 file)
Files folder imageListener (1 file)
Files folder imageStream (1 file)

  Files folder image Files  /  src  /  ZipMerge  /  Zip  /  Core  
File Role Description
Files folder imageExtraField (6 files)
Files folder imageHeader (3 files)
  Plain text file AbstractException.php Class Class file
  Plain text file AbstractZipWriter.php Class Class file
  Plain text file ZipUtils.php Class Class file

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

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

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

  Files folder image Files  /  src  /  ZipMerge  /  Zip  /  File  
File Role Description
  Plain text file 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 folder image Files  /  src  /  ZipMerge  /  Zip  /  Listener  
File Role Description
  Plain text file ZipArchiveListener.php Class Class file

  Files folder image Files  /  src  /  ZipMerge  /  Zip  /  Stream  
File Role Description
  Plain text file ZipMerge.php Class Main Class file

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file MergeZip.Example1.php Example Example showing the use of the ZipMerge Class
  Accessible without login Plain text file 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

Downloadphp-zip-merge-2024-01-09.zip 26KB
Downloadphp-zip-merge-2024-01-09.tar.gz
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Relative Path Download .zip .tar.gz Clean and manage paths before adding them to the zip file Required
Bin String Download .zip .tar.gz Work around cases where mbstring.func_overload is enabled Required
 Version Control Reuses Unique User Downloads Download Rankings  
 100%1
Total:321
This week:0
All time:7,215
This week:164Up