PHPackages                             softcomtecnologia/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. softcomtecnologia/zipper

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

softcomtecnologia/zipper
========================

This is a little neat helper for the ZipArchive methods with handy functions

v12.0.1(1y ago)05.0k↓33.3%MITPHPPHP &gt;=8.2

Since Nov 25Pushed 2mo agoCompare

[ Source](https://github.com/softcomtecnologia/Zipper)[ Packagist](https://packagist.org/packages/softcomtecnologia/zipper)[ Docs](http://github.com/Chumper/zipper)[ RSS](/packages/softcomtecnologia-zipper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (18)Used By (0)

Note
====

[](#note)

I haven't updated this package in a long time except merging PRs. The last time I was using this package was with PHP5. I archived the repository for the reason that I am no longer working with PHP (we all have to move on sometimes) and have no time to take proper care of it anymore.

Feel free to read the code, to fork it or to use it in whatever way you want.

Update 25th February 2020
-------------------------

[](#update-25th-february-2020)

I have merged a PR that includes a security fixe to mitigate zip directory traversal attacks.
**This package is still archived and should be swapped out with another package.**
However, as long as security fixes will come in I see it as my basic obligation to update this package on demand.

Zipper
======

[](#zipper)

[![Build Status](https://camo.githubusercontent.com/9bbc0529ee78158aae6353b1ed31e24a84f7b31c7d5b4a552c60513d4f5e0a9c/68747470733a2f2f7472617669732d63692e6f72672f4368756d7065722f5a69707065722e706e67)](https://travis-ci.org/Chumper/Zipper)

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

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

[](#installation)

1. Add this package to the list of required packages, inside `composer.json`

- for Laravel 5: `"chumper/zipper": "1.0.x"`
- for Laravel 4: `"chumper/zipper": "0.5.x"`

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

- add to providers `Chumper\Zipper\ZipperServiceProvider::class`
- add to aliases `'Zipper' => Chumper\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 \Chumper\Zipper\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');
```

Development
===========

[](#development)

Maybe it is a good idea to add other compression functions like rar, phar or bzip2 etc... Everything is setup for that, if you want just fork and develop further.

If you need other functions or got errors, please leave an issue on github.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance71

Regular maintenance activity

Popularity22

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor3

3 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 ~307 days

Recently: every ~468 days

Total

14

Last Release

190d ago

Major Versions

0.7.0 → v1.0.02017-01-30

v1.0.3 → v2.0.02020-09-15

v2.0.0 → v12.0.02020-09-15

v2.0.1 → v12.0.12025-03-20

PHP version history (6 changes)0.5.0PHP &gt;=5.3.0

0.7.0PHP &gt;=5.4.0

v1.0.1PHP &gt;=5.6.0

v2.0.0PHP &gt;=7.1

v12.0.1PHP &gt;=8.2

v8.1.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/23b53d117e80a86fbcdf5c2755f36dd2c8275c41125d4c11c969cae95605fddb?d=identicon)[softcomtecnologia](/maintainers/softcomtecnologia)

---

Top Contributors

[![Chumper](https://avatars.githubusercontent.com/u/919670?v=4)](https://github.com/Chumper "Chumper (19 commits)")[![aldas](https://avatars.githubusercontent.com/u/2320301?v=4)](https://github.com/aldas "aldas (12 commits)")[![rvitaliy](https://avatars.githubusercontent.com/u/1823711?v=4)](https://github.com/rvitaliy "rvitaliy (12 commits)")[![thecotne](https://avatars.githubusercontent.com/u/1606993?v=4)](https://github.com/thecotne "thecotne (3 commits)")[![VINICIUSOLIVER](https://avatars.githubusercontent.com/u/27225482?v=4)](https://github.com/VINICIUSOLIVER "VINICIUSOLIVER (3 commits)")[![nextlevelshit](https://avatars.githubusercontent.com/u/10194510?v=4)](https://github.com/nextlevelshit "nextlevelshit (2 commits)")[![actionm](https://avatars.githubusercontent.com/u/1145098?v=4)](https://github.com/actionm "actionm (2 commits)")[![plantwebdesign](https://avatars.githubusercontent.com/u/838647?v=4)](https://github.com/plantwebdesign "plantwebdesign (2 commits)")[![bart](https://avatars.githubusercontent.com/u/5200235?v=4)](https://github.com/bart "bart (2 commits)")[![snipe](https://avatars.githubusercontent.com/u/197404?v=4)](https://github.com/snipe "snipe (2 commits)")[![francescoassenza](https://avatars.githubusercontent.com/u/5212035?v=4)](https://github.com/francescoassenza "francescoassenza (1 commits)")[![heslil](https://avatars.githubusercontent.com/u/14540581?v=4)](https://github.com/heslil "heslil (1 commits)")[![ikeedo](https://avatars.githubusercontent.com/u/623353?v=4)](https://github.com/ikeedo "ikeedo (1 commits)")[![inov](https://avatars.githubusercontent.com/u/2234246?v=4)](https://github.com/inov "inov (1 commits)")[![lex111](https://avatars.githubusercontent.com/u/4408379?v=4)](https://github.com/lex111 "lex111 (1 commits)")[![nadjib](https://avatars.githubusercontent.com/u/7357519?v=4)](https://github.com/nadjib "nadjib (1 commits)")[![socieboy](https://avatars.githubusercontent.com/u/7442695?v=4)](https://github.com/socieboy "socieboy (1 commits)")[![vool](https://avatars.githubusercontent.com/u/441840?v=4)](https://github.com/vool "vool (1 commits)")[![xploSEoF](https://avatars.githubusercontent.com/u/7510900?v=4)](https://github.com/xploSEoF "xploSEoF (1 commits)")[![alesf](https://avatars.githubusercontent.com/u/1148574?v=4)](https://github.com/alesf "alesf (1 commits)")

---

Tags

laravelarchivezip

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

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

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

PHPackages © 2026

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