PHPackages                             squareetlabs/zipper - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. squareetlabs/zipper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

squareetlabs/zipper
===================

This is a simple Wrapper around the ZipArchive methods with some handy functions.

v1.0.4(4y ago)0151MITPHPPHP &gt;=7.2.0

Since Nov 22Pushed 4y ago1 watchersCompare

[ Source](https://github.com/squareetlabs/LaravelZipper)[ Packagist](https://packagist.org/packages/squareetlabs/zipper)[ Docs](https://github.com/SquareetLabs/zipper)[ RSS](/packages/squareetlabs-zipper/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (2)Dependencies (4)Versions (5)Used By (0)

Zipper
======

[](#zipper)

[![Build Status](https://camo.githubusercontent.com/85f1f7ea17b1068f93c3936f60abac52eacfdb77c5b49ecf922795c9099ad2c3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73717561726565746c6162732f4c61726176656c5a69707065722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/squareetlabs/Zipper/)[![Code Intelligence](https://camo.githubusercontent.com/d43c6eacf6b1932bacdd5afb8612293f6fffa197b33bbb370c57216998493c7f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73717561726565746c6162732f4c61726176656c5a69707065722f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/g/squareetlabs/Zipper/)[![Latest Stable Version](https://camo.githubusercontent.com/d23a1c28045163686eadce1d70b8de97f240e4071adb8657ca04d77667a8eee5/68747470733a2f2f706f7365722e707567782e6f72672f73717561726565746c6162732f7a69707065722f762f737461626c65)](https://packagist.org/packages/squareetlabs/zipper)[![Total Downloads](https://camo.githubusercontent.com/3e20af213ef63214df1a05a6cf0e1df5526d6a437f24d3cfb0d8732e3a0d4f90/68747470733a2f2f706f7365722e707567782e6f72672f73717561726565746c6162732f7a69707065722f646f776e6c6f616473)](https://packagist.org/packages/squareetlabs/zipper) [![License](https://camo.githubusercontent.com/69af29163bf16702e3444cdda56040372ac039c59da77eda03e3a0e6bc238be8/68747470733a2f2f706f7365722e707567782e6f72672f73717561726565746c6162732f7a69707065722f6c6963656e7365)](https://packagist.org/packages/squareetlabs/zipper)

This is a simple Wrapper around the ZipArchive methods with some handy functions. Installation
------------

[](#installation)

You can install this package via composer:

```
composer require squareetlabs/zipper
```

2. Run `composer update`
3. Go to `app/config/app.php`

- add to providers `Zipper\ZipperServiceProvider::class`
- add to aliases `'Zipper' => Zipper\Zipper::class`

You can now access Zipper with the `Zipper` alias.

Simple example
--------------

[](#simple-example)

```
$files = glob('public/files/*');
Zipper::make('public/test.zip')->add($files)->close();
```

- by default the package will create the `test.zip` in the project route folder but in the example above we changed it to `project_route/public/`.

Another example
---------------

[](#another-example)

```
$zipper = new Zipper;

$zipper->make('test.zip')->folder('test')->add('composer.json');
$zipper->zip('test.zip')->folder('test')->add('composer.json','test');

$zipper->remove('composer.lock');

$zipper->folder('mySuperPackage')->add(
    array(
        'vendor',
        'composer.json'
    ),
);

$zipper->getFileContent('mySuperPackage/composer.json');

$zipper->make('test.zip')->extractTo('',array('mySuperPackage/composer.json'),Zipper::WHITELIST);

$zipper->close();
```

Note: Please be aware that you need to call `->close()` at the end to write the zip file to disk.

You can easily chain most functions, except `getFileContent`, `getStatus`, `close` and `extractTo` which must come at the end of the chain.

The main reason I wrote this little package is the `extractTo` method since it allows you to be very flexible when extracting zips. So you can for example implement an update method which will just override the changed files.

Functions
=========

[](#functions)

make($pathToFile)
-----------------

[](#makepathtofile)

`Create` or `Open` a zip archive; if the file does not exists it will create a new one. It will return the Zipper instance so you can chain easily.

add($files/folder)
------------------

[](#addfilesfolder)

You can add an array of Files, or a Folder and all the files in that folder will then be added, so from the first example we could instead do something like `$files = 'public/files/';`.

addString($filename, $content)
------------------------------

[](#addstringfilename-content)

Add a single file to the zip by specifying a name and the content as strings.

remove($file/s)
---------------

[](#removefiles)

Removes a single file or an array of files from the zip.

folder($folder)
---------------

[](#folderfolder)

Specify a folder to 'add files to' or 'remove files from' from the zip, example

```
Zipper::make('test.zip')->folder('test')->add('composer.json');
Zipper::make('test.zip')->folder('test')->remove('composer.json');
```

listFiles($regexFilter = null)
------------------------------

[](#listfilesregexfilter--null)

Lists all files within archive (if no filter pattern is provided). Use `$regexFilter` parameter to filter files. See [Pattern Syntax](http://php.net/manual/en/reference.pcre.pattern.syntax.php) for regular expression syntax

> NB: `listFiles` ignores folder set with `folder` function

Example: Return all files/folders ending/not ending with '.log' pattern (case insensitive). This will return matches in sub folders and their sub folders also

```
$logFiles = Zipper::make('test.zip')->listFiles('/\.log$/i');
$notLogFiles = Zipper::make('test.zip')->listFiles('/^(?!.*\.log).*$/i');
```

home()
------

[](#home)

Resets the folder pointer.

zip($fileName)
--------------

[](#zipfilename)

Uses the ZipRepository for file handling.

getFileContent($filePath)
-------------------------

[](#getfilecontentfilepath)

Get the content of a file in the zip. This will return the content or false.

getStatus()
-----------

[](#getstatus)

Get the opening status of the zip as integer.

close()
-------

[](#close)

Closes the zip and writes all changes.

extractTo($path)
----------------

[](#extracttopath)

Extracts the content of the zip archive to the specified location, for example

```
Zipper::make('test.zip')->folder('test')->extractTo('foo');
```

This will go into the folder `test` in the zip file and extract the content of that folder only to the folder `foo`, this is equal to using the `Zipper::WHITELIST`.

This command is really nice to get just a part of the zip file, you can also pass a 2nd &amp; 3rd param to specify a single or an array of files that will be

> NB: Php ZipArchive uses internally '/' as directory separator for files/folders in zip. So Windows users should not set whitelist/blacklist patterns with '' as it will not match anything

white listed

> **Zipper::WHITELIST**

```
Zipper::make('test.zip')->extractTo('public', array('vendor'), Zipper::WHITELIST);
```

Which will extract the `test.zip` into the `public` folder but **only** files/folders starting with `vendor` prefix inside the zip will be extracted.

or black listed

> **Zipper::BLACKLIST**Which will extract the `test.zip` into the `public` folder except files/folders starting with `vendor` prefix inside the zip will not be extracted.

```
Zipper::make('test.zip')->extractTo('public', array('vendor'), Zipper::BLACKLIST);
```

> **Zipper::EXACT\_MATCH**

```
Zipper::make('test.zip')
    ->folder('vendor')
    ->extractTo('public', array('composer', 'bin/phpunit'), Zipper::WHITELIST | Zipper::EXACT_MATCH);
```

Which will extract the `test.zip` into the `public` folder but **only** files/folders **exact matching names**. So this will:

- extract file or folder named `composer` in folder named `vendor` inside zip to `public` resulting `public/composer`
- extract file or folder named `bin/phpunit` in `vendor/bin/phpunit` folder inside zip to `public` resulting `public/bin/phpunit`

> **NB:** extracting files/folder from zip without setting Zipper::EXACT\_MATCH When zip has similar structure as below and only `test.bat` is given as whitelist/blacklist argument then `extractTo` would extract all those files and folders as they all start with given string

```
test.zip
 |- test.bat
 |- test.bat.~
 |- test.bat.dir/
    |- fileInSubFolder.log

```

extractMatchingRegex($path, $regex)
-----------------------------------

[](#extractmatchingregexpath-regex)

Extracts the content of the zip archive matching regular expression to the specified location. See [Pattern Syntax](http://php.net/manual/en/reference.pcre.pattern.syntax.php) for regular expression syntax.

Example: extract all files ending with `.php` from `src` folder and its sub folders.

```
Zipper::make('test.zip')->folder('src')->extractMatchingRegex($path, '/\.php$/i');
```

Example: extract all files **except** those ending with `test.php` from `src` folder and its sub folders.

```
Zipper::make('test.zip')->folder('src')->extractMatchingRegex($path, '/^(?!.*test\.php).*$/i');
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~0 days

Total

4

Last Release

1627d ago

PHP version history (2 changes)v1.0.0PHP &gt;=5.6.0

v1.0.3PHP &gt;=7.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f0312df8043f114ad6f9c945a452d4e451bd14cecae570f9772ce937630bce5?d=identicon)[squareetlabs](/maintainers/squareetlabs)

---

Top Contributors

[![jcancig](https://avatars.githubusercontent.com/u/446610?v=4)](https://github.com/jcancig "jcancig (22 commits)")

---

Tags

laravelarchivezip

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/squareetlabs-zipper/health.svg)

```
[![Health](https://phpackages.com/badges/squareetlabs-zipper/health.svg)](https://phpackages.com/packages/squareetlabs-zipper)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M682](/packages/barryvdh-laravel-ide-helper)

PHPackages © 2026

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