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

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

originphp/zip
=============

OriginPHP Zip

2.0.0(5y ago)27581MITPHPPHP &gt;=7.3.0CI failing

Since Dec 20Pushed 5y ago1 watchersCompare

[ Source](https://github.com/originphp/zip)[ Packagist](https://packagist.org/packages/originphp/zip)[ Docs](https://www.originphp.com)[ RSS](/packages/originphp-zip/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (2)Versions (9)Used By (1)

Zip
===

[](#zip)

[![license](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)[![build](https://github.com/originphp/zip/workflows/CI/badge.svg)](https://github.com/originphp/zip/actions)[![coverage](https://camo.githubusercontent.com/d58d824a9b879b1859b3c10cce6c4814419ec8fdde302a361ffdefc08385c787/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6f726967696e7068702f7a69702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/originphp/zip?branch=master)

A ZIP utility for creating and unziping ZIP files.

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

[](#installation)

To install this package

```
$ composer require originphp/zip

```

Static Methods
--------------

[](#static-methods)

The static methods provide a quick way to zip and unzip archives.

### Create a ZIP Archive

[](#create-a-zip-archive)

To create a ZIP archive using a file or directory

```
Zip::zip(__DIR__ .'/src','/backups/today.zip');
```

You can also ZIP multiple files or directories

```
Zip::zip([
    'README.md',
    __DIR__ .'/src'
    ],'/backups/today.zip');
```

You can also pass any of the following options keys

- password: a password used to encrypt the archive with
- compress: default:`true`. Set to `false` to only store the files (without compression)
- encryption: default:`aes256`. This is the encryption method used when using a password. Supported encryption methods: `aes128`,`aes192`,and `aes256`.

> To encrypt files with passwords you need to be using PHP 7.3 or above.

```
Zip::zip(__DIR__ .'/src','/backups/today.zip',[
    'password'=>'passw0rd'
    ]);
```

### Unzip a ZIP Archive

[](#unzip-a-zip-archive)

To unzip a ZIP file

```
Zip::unzip('/backups/today.zip','/a/folder');
```

If any of the files are encrypted you provide a password like this

```
Zip::unzip('/backups/today.zip','/a/folder',[
    'password' => 'passw0rd'
]);
```

Fluent Interface
----------------

[](#fluent-interface)

The ZIP class also provides a fluent interface for working with ZIP archives.

### Create a ZIP Archive

[](#create-a-zip-archive-1)

To create a new ZIP and files and directories. When you add a directory it will add all files and sub directories recursively.

```
$zip = new Zip();
$zip->create('/path/to/file.zip')
    ->add('README.md')
    ->add('src')
    ->save();
```

### Encryption

[](#encryption)

> To encrypt files with passwords you need to be using PHP 7.3 or above.

To encrypt all the files in the archive, call the `encrypt` method after adding the files, you can optionally supply the encryption method. Supported encryption methods are `aes128`,`aes192` and `aes256`.

```
$zip = new Zip();
$zip->create('/path/to/file.zip')
    ->add('README.md')
    ->add('src')
    ->encrypt('passw0rd')
    ->save();
```

If just want to encrypt certain files

```
$zip = new Zip();
$zip->create('/path/to/file.zip')
    ->add('README.md')
    ->add('Financials.xlsx',['password' => 'secret'])
    ->save();
```

### Compression

[](#compression)

If you just want to store a file in the ZIP archive without compression you can set `compress` to `false`.

```
$zip = new Zip();
$zip->create('/path/to/file.zip')
    ->add('logo.jpg',['compress'=>false])
    ->save();
```

### Unzip a ZIP Archive

[](#unzip-a-zip-archive-1)

To extract files from a ZIP file

```
$zip = new Zip();
$zip->open('/path/to/file.zip')
    ->extract('/destination/folder')
```

If the ZIP file has encrypted files

```
$zip = new Zip();
$zip->open('/path/to/file.zip')
    ->extract('/destination/folder',['password'=>'foo']);
```

You can also extract selected files

```
$zip = new Zip();
$zip->open('/path/to/file.zip')
    ->extract('/destination/folder',[
        'files'=>[
            'README.md',
            'LICENSE.md'
        ]
    ]);
```

### Listing contents

[](#listing-contents)

To list contents of a ZIP file

```
$zip = new Zip();
$list = $zip->open('/path/to/file.zip')
            ->list();
```

This will output like this

```
Array
(
    [0] => Origin\Zip\FileObject Object
        (
            [name] => README.md
            [size] => 666
            [timestamp] => 1576656596
            [compressedSize] => 371
            [encrypted] => 1
        )
)

```

You can also just list files from within a folder of the ZIP file

```
$zip = new Zip();
$testFiles = $zip->open('/path/to/file.zip')
                 ->list('tests');
```

### Getting contents of a file

[](#getting-contents-of-a-file)

To get the contents of a file

```
$zip = new Zip();
$contents = $zip->open('/path/to/file.zip')
                 ->get('README.md');
```

### Renaming

[](#renaming)

To rename a file in a ZIP archive

```
$zip = new Zip();
$zip->open('/path/to/file.zip')
    ->rename('foo.txt','bar.txt');
```

### Deleting Files

[](#deleting-files)

To delete a file from a ZIP archive

```
$zip = new Zip();
$zip->open('/path/to/file.zip')
    ->delete('tests/ControllerTest.php');
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

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

Recently: every ~18 days

Total

8

Last Release

1959d ago

Major Versions

0.1.0 → 1.0.02020-01-15

1.3.0 → 2.0.02021-01-04

PHP version history (3 changes)0.1.0PHP ^7.2.0

1.0.2PHP &gt;=7.2.0

2.0.0PHP &gt;=7.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e8a821333d9c7b7bc2ad3d164d142f65cd3912dea78033d31f76b0f19ba8a0c?d=identicon)[originphp](/maintainers/originphp)

---

Top Contributors

[![jamielsharief](https://avatars.githubusercontent.com/u/20553479?v=4)](https://github.com/jamielsharief "jamielsharief (35 commits)")

---

Tags

compressionarchiveziporiginPHP

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[alchemy/zippy

Zippy, the archive manager companion

47522.6M51](/packages/alchemy-zippy)

PHPackages © 2026

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