PHPackages                             motekar/laravel-zip - 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. motekar/laravel-zip

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

motekar/laravel-zip
===================

Create and Manage Zip Archives in Laravel

v1.0.2(1y ago)0173Apache-2.0PHPPHP ^8.0

Since Dec 28Pushed 1y agoCompare

[ Source](https://github.com/motekar/laravel-zip)[ Packagist](https://packagist.org/packages/motekar/laravel-zip)[ Docs](http://github.com/motekar/laravel-zip)[ RSS](/packages/motekar-laravel-zip/feed)WikiDiscussions master Synced 1mo ago

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

Laravel Zip - Create and Manage Zip Archives in Laravel
=======================================================

[](#laravel-zip---create-and-manage-zip-archives-in-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f1ef5ea1ce5d78305a966568d0b70b66068e97ade71969f3d7058775ca8732bb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f74656b61722f6c61726176656c2d7a69702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/motekar/laravel-zip)[![GitHub Tests Action Status](https://camo.githubusercontent.com/af4f5667d1f875bddda3f9ea9557826ab0378e7b36c6d47c1e0e5708de55336a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f74656b61722f6c61726176656c2d7a69702f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/motekar/laravel-zip/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/d26f1a453938367ca44bb1442e392e26008dc902b2c55c2216b345e5ffa5d7b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f74656b61722f6c61726176656c2d7a69702f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/motekar/laravel-zip/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/17046c58169852be27453b4d6ca38b5e497f5598ce0e29378434a78b6788e72f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f74656b61722f6c61726176656c2d7a69702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/motekar/laravel-zip)

This package provides a simple and intuitive way to create and manage Zip archives in Laravel applications. It wraps PHP's ZipArchive class with additional convenience methods and fluent syntax.

Quick Example
-------------

[](#quick-example)

```
use Motekar\LaravelZip\Facades\Zip;

Zip::make(storage_path('images.zip'))
    ->add(glob(storage_path('images/*')))
    ->close();
```

This code creates a zip file named `images.zip` in the storage directory, containing all files from the `storage/images/` folder.

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

[](#installation)

Install the package via Composer:

```
composer require motekar/laravel-zip
```

Usage
-----

[](#usage)

```
use Motekar\LaravelZip\Facades\Zip;
use Motekar\LaravelZip\ZipManager;

// Create a zip file and add files
$zip = Zip::make('test.zip')
    ->folder('test')
    ->add('composer.json');

// Add a file with a specific name
$zip = Zip::make('test.zip')
    ->folder('test')
    ->add('composer.json', 'test');

// Remove a file from the archive
$zip->remove('composer.lock');

// Add multiple files to a specific folder
$zip->folder('mySuperPackage')->add([
    'vendor',
    'composer.json'
]);

// Get file content from the archive
$content = $zip->getFileContent('mySuperPackage/composer.json');

// Extract specific files using whitelist
$zip->make('test.zip')
    ->extractTo('', ['mySuperPackage/composer.json'], ZipManager::WHITELIST)
    ->close();
```

**Important Notes:**

1. Always call `->close()` at the end to write changes to disk
2. Most methods are chainable except:
    - `getFileContent`
    - `getStatus`
    - `close`
    - `extractTo`

API Reference
-------------

[](#api-reference)

### make($pathToFile)

[](#makepathtofile)

Creates or opens a zip archive. If the file doesn't exist, it creates a new one. Returns the ZipManager instance for method chaining.

### add($filesOrFolder)

[](#addfilesorfolder)

Adds files or folders to the archive. Accepts:

- An array of file paths
- A single folder path (all files in the folder will be added)

### addString($filename, $content)

[](#addstringfilename-content)

Adds a file to the archive using string content.

### remove($files)

[](#removefiles)

Removes files from the archive. Accepts:

- A single file path
- An array of file paths

### folder($folder)

[](#folderfolder)

Sets the working folder for subsequent operations.

### listFiles($regexFilter = null)

[](#listfilesregexfilter--null)

Lists files in the archive. Optionally filters files using a regex pattern.

**Note:** Ignores the folder set with `folder()`

**Examples:**

```
// Get all .log files
$logFiles = Zip::make('test.zip')->listFiles('/\.log$/i');

// Get all non-.log files
$notLogFiles = Zip::make('test.zip')->listFiles('/^(?!.*\.log).*$/i');
```

### home()

[](#home)

Resets the folder pointer to the root.

### getFileContent($filePath)

[](#getfilecontentfilepath)

Returns the content of a file from the archive or false if not found.

### getStatus()

[](#getstatus)

Returns the opening status of the zip archive as an integer.

### close()

[](#close)

Writes all changes and closes the archive.

### extractTo($path, $files = \[\], $flags = 0)

[](#extracttopath-files---flags--0)

Extracts archive contents to the specified path. Supports:

- **ZipManager::WHITELIST**: Extract only specified files
- **ZipManager::BLACKLIST**: Extract all except specified files
- **ZipManager::EXACT\_MATCH**: Match file names exactly

**Examples:**

```
use Motekar\LaravelZip\Facades\Zip;
use Motekar\LaravelZip\ZipManager;

// Whitelist example
Zip::make('test.zip')
    ->extractTo('public', ['vendor'], ZipManager::WHITELIST);

// Blacklist example
Zip::make('test.zip')
    ->extractTo('public', ['vendor'], ZipManager::BLACKLIST);

// Exact match example
Zip::make('test.zip')
    ->folder('vendor')
    ->extractTo('public', ['composer', 'bin/phpunit'], ZipManager::WHITELIST | ZipManager::EXACT_MATCH);
```

### extractMatchingRegex($path, $regex)

[](#extractmatchingregexpath-regex)

Extracts files matching a regular expression pattern.

**Examples:**

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

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

**Important Notes:**

1. PHP's ZipArchive uses '/' as the directory separator
2. Windows users should use '/' in patterns instead of ''

Credits
-------

[](#credits)

- [Fauzie Rofi](https://github.com/fauzie811)
- [Nils Plaschke](http://nilsplaschke.de)
- [All Contributors](../../contributors)

License
-------

[](#license)

This package is open-source software licensed under the [Apache Version 2.0 license](LICENSE.md).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance41

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

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

Total

3

Last Release

498d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6152a48866fbaa42382bc558b603530053558043da5076f5c743edd0093d58ff?d=identicon)[fauzie811](/maintainers/fauzie811)

---

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)")[![fauzie811](https://avatars.githubusercontent.com/u/318095?v=4)](https://github.com/fauzie811 "fauzie811 (9 commits)")[![thecotne](https://avatars.githubusercontent.com/u/1606993?v=4)](https://github.com/thecotne "thecotne (3 commits)")[![actionm](https://avatars.githubusercontent.com/u/1145098?v=4)](https://github.com/actionm "actionm (2 commits)")[![nextlevelshit](https://avatars.githubusercontent.com/u/10194510?v=4)](https://github.com/nextlevelshit "nextlevelshit (2 commits)")[![plantwebdesign](https://avatars.githubusercontent.com/u/838647?v=4)](https://github.com/plantwebdesign "plantwebdesign (2 commits)")[![snipe](https://avatars.githubusercontent.com/u/197404?v=4)](https://github.com/snipe "snipe (2 commits)")[![bart](https://avatars.githubusercontent.com/u/5200235?v=4)](https://github.com/bart "bart (2 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)")[![arthurprogramming](https://avatars.githubusercontent.com/u/4672300?v=4)](https://github.com/arthurprogramming "arthurprogramming (1 commits)")

---

Tags

laravelarchivezip

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/motekar-laravel-zip/health.svg)

```
[![Health](https://phpackages.com/badges/motekar-laravel-zip/health.svg)](https://phpackages.com/packages/motekar-laravel-zip)
```

###  Alternatives

[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.3M74](/packages/unisharp-laravel-filemanager)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[spatie/laravel-google-cloud-storage

Google Cloud Storage filesystem driver for Laravel

2408.9M13](/packages/spatie-laravel-google-cloud-storage)[zanysoft/laravel-zip

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

3142.8M15](/packages/zanysoft-laravel-zip)[madnest/madzipper

Easier zip file handling for Laravel applications.

1382.3M6](/packages/madnest-madzipper)[zing/laravel-flysystem-obs

Flysystem Adapter for OBS

1211.2k](/packages/zing-laravel-flysystem-obs)

PHPackages © 2026

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