victor78/yii2-zipper

Yii2-Zipper is archiving component for Yii2.

Maintainers

Package info

github.com/victor78/yii2-zipper

Wiki

Type:yii2-extension

pkg:composer/victor78/yii2-zipper

Statistics

Installs: 28 674

Dependents: 2

Suggesters: 0

Stars: 1

Open Issues: 2

v1.0.0 2026-06-07 15:55 UTC

This package is not auto-updated.

Last update: 2026-06-07 16:00:53 UTC


README

CI Latest Stable Version License Total Downloads

Archiving extension for Yii2 Framework - zip, tar, tar.gz, tar.bz2, 7zip (for zip archive with supporting passwords). It's a shell over ZippyExt.

Расширение для архивации в Yii2 Framework - в виде zip, tar, tar.gz, tar.bz2, 7zip (только для zip архива - в том числе с поддержкой паролей).

English:

Русский:

Requirements

  • PHP >= 8.1
  • Yii2 framework
  • ZippyExt ^1.0
  • For zip type — the zip console utility or the PHP zip extension.
  • For tar, tar.gz, tar.bz2 — GNU tar or BSD tar.
  • For 7zip — the 7za or 7z binary available in PATH.

PHP Compatibility

yii2-zipper zippy-ext PHP
1.x ^1.0 8.1–8.3
0.x ~0.0.4 7.0+

Installation

The preferred way to install this extension is through composer.

Either run

composer require victor78/yii2-zipper:"^1.0"

or add

"victor78/yii2-zipper": "^1.0"

to the require section of your composer.json.

Configuration

'type' and 'password' are optional.

return [
    //....
    'components' => [
        'zipper' => [
            'class' => 'Victor78\Zipper\Zipper', //required
            'type' => '7zip', //or 'zip' (default), 'tar', 'tar.gz', 'tar.bz2'
            'password' => 'password12345', //optional, only for 7zip type
        ],
    ]
];

How to use

To create archive:

//files to archive
$files = [
  '/path/to/file1',
  '/path/to/file2',
];
//to create tar archive
$tarArchive = Yii::$app->zipper->create('/tmp/archive.tar', $files, true, 'tar');

//to create zip archive by 7zip with password 
$sevenZipArchive = Yii::$app->zipper->create('/tmp/archive.zip', $files, true, '7zip', 'password12345');
//or, if you've configured zipper component like in the example above:
$sevenZipArchive = Yii::$app->zipper->create('/tmp/archive.zip', $files);


$zipArchive = Yii::$app->zipper->create('/tmp/archive.zip', $files, true, 'zip'); 

To open archive and extract:

$zipArchive = Yii::$app->zipper->open('/tmp/archive.zip', 'zip');
$tarArchive = Yii::$app->zipper->open('/tmp/archive.tar', 'tar');
$sevenZipArchive = Yii::$app->zipper->open('/tmp/archive.zip', '7zip');
//open 7zip with password
$sevenZipArchiveEncrypted = Yii::$app->zipper->open('/tmp/archive.zip', '7zip', 'password12345');

$zipArchive->extract('/tmp/extracted/');

When you configure zipper component with optional properties 'type' and 'password', they will be used as default fourth and fifth parameters in the create method, and as default second and third parameters in the open method. If you use these parameters in the methods explicitly, they will overwrite the properties from the config. You can leave out the properties in the config and the parameters in the methods entirely - in this case Zipper will try to understand which adapter to use, but it doesn't work with a 7zip archive.

Both methods return an Archive object. You can find the details about how to use this object and other information in the documentation of the ZippyExt library.

Установка

Предпочтительным способом установки является при помощи composer.

Либо командой из консоли

composer require victor78/yii2-zipper:"^1.0"

либо включением в composer.json в секцию require.

"victor78/yii2-zipper": "^1.0"

Настройка

'type' и 'password' - опциональны.

return [
    //....
    'components' => [
        'zipper' => [
            'class' => 'Victor78\Zipper\Zipper', //required
            'type' => '7zip', //или: 'zip' (по умолчанию), 'tar', 'tar.gz', 'tar.bz2'
            'password' => 'password12345', //опционально, работает только при типе 7zip
        ],
    ]
];

Как использовать

Для создания архива:

//files to archive
$files = [
  '/path/to/file1',
  '/path/to/file2',
];
//создать tar архив
$tarArchive = Yii::$app->zipper->create('/tmp/archive.tar', $files, true, 'tar');

//создать zip архив с паролем при помощи 7zip  
$sevenZipArchive = Yii::$app->zipper->create('/tmp/archive.zip', $files, true, '7zip', 'password12345');
//или, если вы настроили компонент Zipper как в примере выше:
$sevenZipArchive = Yii::$app->zipper->create('/tmp/archive.zip', $files);


$zipArchive = Yii::$app->zipper->create('/tmp/archive.zip', $files, true, 'zip'); 

Открыть и распаковать архив:

$zipArchive = Yii::$app->zipper->open('/tmp/archive.zip', 'zip');
$tarArchive = Yii::$app->zipper->open('/tmp/archive.tar', 'tar');
$sevenZipArchive = Yii::$app->zipper->open('/tmp/archive.zip', '7zip');
//открыть запароленный zip созданный при помощи 7zip 
$sevenZipArchiveEncrypted = Yii::$app->zipper->open('/tmp/archive.zip', '7zip', 'password12345');

$zipArchive->extract('/tmp/extracted/');

Если вы настроили компонент Zipper с опциональными свойствами 'type' и 'password', они будут использованы как дефолтные четвёртый и пятый параметры в методе create и второй и третий параметры в методе open. Если эти параметры в этих методах указываются явно, то они переписывают свойства из конфига. Вы можете опустить свойства из конфига и параметры в методах вообще - в таком случае Zipper попытается самостоятельно понять какой именно адаптер какого архиватора использовать, но это точно не будет работать в случае zip архива, созданного при помощи 7zip.

Оба метода возвращают объект Archive. Вы можете найти детали о том, как использовать данный объект и другую информацию в документации к библиотеке ZippyExt.

Требования

  • PHP >= 8.1, фреймворк Yii2 и пакет ZippyExt ^1.0.
  • Для архивирования в чистый zip используется утилита zip или расширение PHP для zip, так что или утилита, или расширение должны быть установлены на сервере для упаковки и распаковки zip.
  • Для tar, tar.gz, tar.bz2 Zipper пытается использовать GNU tar или BSD tar, один из них должен быть установлен на сервере для этих типов архивов.
  • Для упаковки/распаковки zip при помощи 7zip, на сервере должна быть установлена утилита 7za или 7z.