PHPackages                             maennchen/zipstream-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. maennchen/zipstream-php

ActiveLibrary[File &amp; Storage](/categories/file-storage)

maennchen/zipstream-php
=======================

ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.

3.2.1(5mo ago)1.9k286.3M—9.1%113[2 issues](https://github.com/maennchen/ZipStream-PHP/issues)20MITPHPCI passing

Since Nov 13Pushed 6d ago19 watchersCompare

[ Source](https://github.com/maennchen/ZipStream-PHP)[ Packagist](https://packagist.org/packages/maennchen/zipstream-php)[ GitHub Sponsors](https://github.com/maennchen)[ RSS](/packages/maennchen-zipstream-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (44)Used By (20)

ZipStream-PHP
=============

[](#zipstream-php)

[![Main Branch](https://github.com/maennchen/ZipStream-PHP/actions/workflows/branch_main.yml/badge.svg)](https://github.com/maennchen/ZipStream-PHP/actions/workflows/branch_main.yml)[![Coverage Status](https://camo.githubusercontent.com/06cd1693a483ac69376782eb1f9512d9259b6581be4ef9eea0789574a461d8f1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d61656e6e6368656e2f5a697053747265616d2d5048502f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/maennchen/ZipStream-PHP?branch=main)[![Latest Stable Version](https://camo.githubusercontent.com/26e8d62cdb7852552ae2fae662deae92f03a4a613e5a47d0d482a79fc2962ced/68747470733a2f2f706f7365722e707567782e6f72672f6d61656e6e6368656e2f7a697073747265616d2d7068702f762f737461626c65)](https://packagist.org/packages/maennchen/zipstream-php)[![Total Downloads](https://camo.githubusercontent.com/2bbc4a8b9fa3ddc4250264df81acbe5030fe8996cb5ed76502b3a5b690d07e47/68747470733a2f2f706f7365722e707567782e6f72672f6d61656e6e6368656e2f7a697073747265616d2d7068702f646f776e6c6f616473)](https://packagist.org/packages/maennchen/zipstream-php)[![OpenSSF Best Practices](https://camo.githubusercontent.com/4d1f1ed7935a1d587af69f74b3c6fafba91d59d09cba13fe53abe2713f9c5970/68747470733a2f2f7777772e626573747072616374696365732e6465762f70726f6a656374732f393532342f6261646765)](https://www.bestpractices.dev/projects/9524)[![OpenSSF Scorecard](https://camo.githubusercontent.com/045e2dc25dbd973a08ad9d961c78c72f63c900d12273a477695a36371f8febd9/68747470733a2f2f6170692e73636f7265636172642e6465762f70726f6a656374732f6769746875622e636f6d2f6d61656e6e6368656e2f5a697053747265616d2d5048502f6261646765)](https://scorecard.dev/viewer/?uri=github.com/maennchen/ZipStream-PHP)

Unstable Branch
---------------

[](#unstable-branch)

The `main` branch is not stable. Please see the [releases](https://github.com/maennchen/ZipStream-PHP/releases) for a stable version.

Overview
--------

[](#overview)

A fast and simple streaming zip file downloader for PHP. Using this library will save you from having to write the Zip to disk. You can directly send it to the user, which is much faster. It can work with S3 buckets or any PSR7 Stream.

Please see the [LICENSE](LICENSE) file for licensing and warranty information.

Installation
------------

[](#installation)

Simply add a dependency on maennchen/zipstream-php to your project's `composer.json` file if you use Composer to manage the dependencies of your project. Use following command to add the package to your project's dependencies:

```
composer require maennchen/zipstream-php
```

Usage
-----

[](#usage)

For detailed instructions, please check the [Documentation](https://maennchen.github.io/ZipStream-PHP/).

```
// Autoload the dependencies
require 'vendor/autoload.php';

// create a new zipstream object
$zip = new ZipStream\ZipStream(
    outputName: 'example.zip',

    // enable output of HTTP headers
    sendHttpHeaders: true,
);

// create a file named 'hello.txt'
$zip->addFile(
    fileName: 'hello.txt',
    data: 'This is the contents of hello.txt',
);

// add a file named 'some_image.jpg' from a local file 'path/to/image.jpg'
$zip->addFileFromPath(
    fileName: 'some_image.jpg',
    path: 'path/to/image.jpg',
);

// finish the zip stream
$zip->finish();
```

### Callback Output

[](#callback-output)

You can stream ZIP data to a custom callback function instead of directly to the browser:

```
use ZipStream\ZipStream;
use ZipStream\Stream\CallbackStreamWrapper;

// Stream to a callback function with proper file handling
$outputFile = fopen('output.zip', 'wb');
$backupFile = fopen('backup.zip', 'wb');

$zip = new ZipStream(
    outputStream: CallbackStreamWrapper::open(function (string $data) use ($outputFile, $backupFile) {
        // Handle ZIP data as it's generated
        fwrite($outputFile, $data);

        // Send to multiple destinations efficiently
        echo $data; // Browser
        fwrite($backupFile, $data); // Backup file
    }),
    sendHttpHeaders: false,
);

$zip->addFile('hello.txt', 'Hello World!');
$zip->finish();

// Clean up resources
fclose($outputFile);
fclose($backupFile);
```

Questions
---------

[](#questions)

**💬 Questions? Please Read This First!**

If you have a question about using this library, please *do not email the authors directly*. Instead, head over to the [GitHub Discussions](https://github.com/maennchen/ZipStream-PHP/discussions)page — your question might already be answered there! Using Discussions helps build a shared knowledge base, so others can also benefit from the answers. If you need dedicated 1:1 support, check out the options available on [@maennchen's sponsorship page](https://github.com/sponsors/maennchen?frequency=one-time&sponsor=maennchen).

Upgrade to version 3.1.2
------------------------

[](#upgrade-to-version-312)

- Minimum PHP Version: `8.2`

Upgrade to version 3.0.0
------------------------

[](#upgrade-to-version-300)

### General

[](#general)

- Minimum PHP Version: `8.1`
- Only 64bit Architecture is supported.
- The class `ZipStream\Option\Method` has been replaced with the enum `ZipStream\CompressionMethod`.
- Most classes have been flagged as `@internal` and should not be used from the outside. If you're using internal resources to extend this library, please open an issue so that a clean interface can be added &amp; published. The externally available classes &amp; enums are:
    - `ZipStream\CompressionMethod`
    - `ZipStream\Exception*`
    - `ZipStream\ZipStream`

### Archive Options

[](#archive-options)

- The class `ZipStream\Option\Archive` has been replaced in favor of named arguments in the `ZipStream\ZipStream` constructor.
- The archive options `largeFileSize` &amp; `largeFileMethod` has been removed. If you want different `compressionMethods` based on the file size, you'll have to implement this yourself.
- The archive option `httpHeaderCallback` changed the type from `callable` to `Closure`.
- The archive option `zeroHeader` has been replaced with the option `defaultEnableZeroHeader` and can be overridden for every file. Its default value changed from `false` to `true`.
- The archive option `statFiles` was removed since the library no longer checks filesizes this way.
- The archive option `deflateLevel` has been replaced with the option `defaultDeflateLevel` and can be overridden for every file.
- The first argument (`name`) of the `ZipStream\ZipStream` constructor has been replaced with the named argument `outputName`.
- Headers are now also sent if the `outputName` is empty. If you do not want to automatically send http headers, set `sendHttpHeaders` to `false`.

### File Options

[](#file-options)

- The class `ZipStream\Option\File` has been replaced in favor of named arguments in the `ZipStream\ZipStream->addFile*` functions.
- The file option `method` has been renamed to `compressionMethod`.
- The file option `time` has been renamed to `lastModificationDateTime`.
- The file option `size` has been renamed to `maxSize`.

Upgrade to version 2.0.0
------------------------

[](#upgrade-to-version-200)

Upgrade to version 1.0.0
------------------------

[](#upgrade-to-version-100)

Contributing
------------

[](#contributing)

ZipStream-PHP is a collaborative project. Please take a look at the [.github/CONTRIBUTING.md](.github/CONTRIBUTING.md) file.

Version Support
---------------

[](#version-support)

Versions are supported according to the table below.

Please do not open any pull requests contradicting the current version support status.

Careful: Always check the `README` on `main` for up-to-date information.

VersionNew FeaturesBugfixesSecurity*3*✓✓✓*2*✗✗✓*1*✗✗✗0✗✗✗This library aligns itself with the PHP core support. New features and bugfixes will only target PHP versions according to their current status.

See:

About the Authors
-----------------

[](#about-the-authors)

- Paul Duncan  -
- Jonatan Männchen  -
- Jesse G. Donat  -
- Nicolas CARPi  -
- Nik Barham  -

###  Health Score

77

—

ExcellentBetter than 100% of packages

Maintenance87

Actively maintained with recent releases

Popularity81

Widely adopted with strong download metrics

Community52

Growing community involvement

Maturity76

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~116 days

Recently: every ~106 days

Total

39

Last Release

160d ago

Major Versions

v0.5.2 → v1.0.0-alpha.12018-04-02

1.2.0 → 2.0.02020-02-23

v1.x-dev → 2.2.32022-11-25

2.4.0 → 3.0.0-beta.12022-12-14

v2.x-dev → 3.1.0-beta.12023-04-27

PHP version history (6 changes)0.2.2PHP &gt;= 5.3

v0.4.1PHP &gt;= 5.6

v0.5.0PHP &gt;= 7.0

v1.0.0-alpha.1PHP &gt;= 7.1

2.2.0PHP ^8.0

2.2.1PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a57a02ba022451a54d4b65e227ce3d032cadc638a644c2d4b56f0313632ee656?d=identicon)[donatj](/maintainers/donatj)

![](https://www.gravatar.com/avatar/b754d00ecd2ebfbdfac4ba7995aff98fbbf729c9879756e7048acc49f31bcea6?d=identicon)[maennchen](/maintainers/maennchen)

![](https://www.gravatar.com/avatar/a4d563de9a7752150636218e6457933c7c27ceedddb6e234540aae56eb9ceb69?d=identicon)[NicolasCARPi](/maintainers/NicolasCARPi)

---

Top Contributors

[![maennchen](https://avatars.githubusercontent.com/u/333918?v=4)](https://github.com/maennchen "maennchen (172 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (103 commits)")[![donatj](https://avatars.githubusercontent.com/u/133747?v=4)](https://github.com/donatj "donatj (57 commits)")[![NicolasCARPi](https://avatars.githubusercontent.com/u/3043706?v=4)](https://github.com/NicolasCARPi "NicolasCARPi (24 commits)")[![leftdevel](https://avatars.githubusercontent.com/u/843337?v=4)](https://github.com/leftdevel "leftdevel (3 commits)")[![PaolaRuby](https://avatars.githubusercontent.com/u/79208489?v=4)](https://github.com/PaolaRuby "PaolaRuby (3 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (3 commits)")[![andrejpavlovic](https://avatars.githubusercontent.com/u/983644?v=4)](https://github.com/andrejpavlovic "andrejpavlovic (2 commits)")[![ogyr](https://avatars.githubusercontent.com/u/1782?v=4)](https://github.com/ogyr "ogyr (2 commits)")[![pfofi](https://avatars.githubusercontent.com/u/7479939?v=4)](https://github.com/pfofi "pfofi (2 commits)")[![sagara-](https://avatars.githubusercontent.com/u/310250?v=4)](https://github.com/sagara- "sagara- (2 commits)")[![stil](https://avatars.githubusercontent.com/u/714004?v=4)](https://github.com/stil "stil (2 commits)")[![monkeywithacupcake](https://avatars.githubusercontent.com/u/7316730?v=4)](https://github.com/monkeywithacupcake "monkeywithacupcake (1 commits)")[![mpesari](https://avatars.githubusercontent.com/u/11061725?v=4)](https://github.com/mpesari "mpesari (1 commits)")[![mtak3](https://avatars.githubusercontent.com/u/1726154?v=4)](https://github.com/mtak3 "mtak3 (1 commits)")[![dabinat](https://avatars.githubusercontent.com/u/18251622?v=4)](https://github.com/dabinat "dabinat (1 commits)")[![teliov](https://avatars.githubusercontent.com/u/11404406?v=4)](https://github.com/teliov "teliov (1 commits)")[![Chris53897](https://avatars.githubusercontent.com/u/7104259?v=4)](https://github.com/Chris53897 "Chris53897 (1 commits)")[![tomschlick](https://avatars.githubusercontent.com/u/70184?v=4)](https://github.com/tomschlick "tomschlick (1 commits)")[![Ph0tonic](https://avatars.githubusercontent.com/u/5320541?v=4)](https://github.com/Ph0tonic "Ph0tonic (1 commits)")

---

Tags

phpstreamstream-httpstreaming-zipzipzipstream-phpstreamzip

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/maennchen-zipstream-php/health.svg)

```
[![Health](https://phpackages.com/badges/maennchen-zipstream-php/health.svg)](https://phpackages.com/packages/maennchen-zipstream-php)
```

###  Alternatives

[nelexa/zip

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, BZIP2 compression, external file attributes and ZIP64 extensions. Alternative ZipArchive. It does not require php-zip extension.

4967.4M112](/packages/nelexa-zip)[phpzip/phpzip

Package to create and stream archives of compressed files in ZIP format with PHP 5.3+

124840.7k9](/packages/phpzip-phpzip)[zanysoft/laravel-zip

laravel-zip is the world's leading zip utility for file compression and backup.

3142.8M15](/packages/zanysoft-laravel-zip)[wapmorgan/unified-archive

UnifiedArchive - an archive manager with unified interface of working with all popular archive formats (zip/7z/rar/gz/bz2/xz/cab/tar/tar.gz/tar.bz2/tar.x/tar.Z/...) for PHP with ability for listing, reading, extracting and creation + built-in console archive manager.

2791.6M7](/packages/wapmorgan-unified-archive)[league/flysystem-ziparchive

ZIP filesystem adapter for Flysystem.

1039.3M58](/packages/league-flysystem-ziparchive)[barracudanetworks/archivestream-php

A library for dynamically streaming dynamic tar or zip files without the need to have the complete file stored on the server.

77192.2k1](/packages/barracudanetworks-archivestream-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
