A symfony Response to build and stream Zip on the fly

1.0 2016-10-17 13:52 UTC

This package is auto-updated.

Last update: 2022-06-09 08:19:51 UTC


Largely inspired by ZipStream-PHP, PHPZip and of course, the ZIP specifications.


Require wamania/zip-streamed-response-bundle into your composer.json file:

    "require": {
        "wamania/zip-streamed-response-bundle": "dev-master"

Register the bundle in app/AppKernel.php:

// app/AppKernel.php
public function registerBundles()
    return array(
        // ...
        new Wamania\ZipStreamedResponseBundle\ZipStreamedResponseBundle(),


In your controller :

// ....
use Wamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamer;
use Wamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamerFile;
use Wamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamerBigFile;
use Wamania\ZipStreamedResponseBundle\Response\ZipStreamedResponse;

class DefaultController extends Controller
     * @Route("/", name="homepage")
    public function indexAction()
        $zipStreamer = new ZipStreamer('test.zip');
        // Auto switch files above switchAboveSize to "big files"
        ZipStreamer::setAutoSwitch(false/true); // default = true
        // If autoSwitch==true, files above $switchAboveSize will switch to "big files"
        ZipStreamer::setSwitchAboveSize(16777216); // default = 16Mb
        // For big file, size of the buffer for fread
        ZipStreamerBigFile::setBufferSize(1048576); //default = 1Mb

        // first string is localpath on hdd, second is pathname in zip
        // you can send directly a ZipStreamerFile object
          new ZipStreamerFile(
        // Big files are send by stream instead of being charged whole in RAM
        // Big files are NOT compressed
        // or, directly send a ZipStreamerBigFile object
          new ZipStreamerBigFile(

        return new ZipStreamedResponse($zipStreamer);