PHP code example of victor78 / yii2-zipper

1. Go to this page and download the library: Download victor78/yii2-zipper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

victor78 / yii2-zipper example snippets


return [
    //....
    'components' => [
        'zipper' => [
            'class' => 'Victor78\Zipper\Zipper', //12345', //optional, only for 7zip type
        ],
    ]
];

//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'); 


$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/');

return [
    //....
    'components' => [
        'zipper' => [
            'class' => 'Victor78\Zipper\Zipper', //assword' => '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/');

php composer.phar 

php composer.phar