Yii2-Zipper
Archiving extension for Yii2 Framework - zip, tar, tar.gz, tar.bz2, 7zip (for zip archive with supporting passwords).
It's shell over ZippyExt., (*1)
Π Π°ΡΡΠΈΡΠ΅Π½ΠΈΠ΅ Π΄Π»Ρ Π°ΡΡ
ΠΈΠ²Π°ΡΠΈΠΈ Π² Yii2 Framework - Π² Π²ΠΈΠ΄Π΅ zip, tar, tar.gz, tar.bz2, 7zip (ΡΠΎΠ»ΡΠΊΠΎ Π΄Π»Ρ zip Π°ΡΡ
ΠΈΠ²Π° - Π² ΡΠΎΠΌ ΡΠΈΡΠ»Π΅ Ρ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΊΠΎΠΉ ΠΏΠ°ΡΠΎΠ»Π΅ΠΉ)., (*2)
English:
* Installation
* Configuration
* How to use
* Requirements, (*3)
Π ΡΡΡΠΊΠΈΠΉ:
* Π£ΡΡΠ°Π½ΠΎΠ²ΠΊΠ°
* ΠΠ°ΡΡΡΠΎΠΉΠΊΠ°
* ΠΠ°ΠΊ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ
* Π’ΡΠ΅Π±ΠΎΠ²Π°Π½ΠΈΡ, (*4)
Installation
The preferred way to install this extension is through composer., (*5)
Either run, (*6)
php composer.phar require --prefer-dist victor78/yii2-zipper:"~0.0.4"
or add, (*7)
"victor78/yii2-zipper": "~0.0.4"
to the require section of your composer.json., (*8)
Configuration
'type' and 'password' are optional., (*9)
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:, (*10)
//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:, (*11)
$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 create method, and as default second and third parameters in open method. If you use parameters in this methods obviously, they will overwrite properties from the config.
You can leave out properties in the config and the parameters in the methods at all - in this case Zipper will trying understand which adapter to use, but it doesn't work with 7zip archive., (*12)
Both this methods return Archive object. You can find the details about how to use this object and other information in documentation of ZippyExt libruary., (*13)
Requirements
- For zip type Zipper try to use console command zip or php zip extension, so one of them is required on server for zipping.
- For tar, tar.gz, tar.bz2 Zipper try to use GNU tar and BSD tar, so one ofo them is required on server for these ways of arching.
- For zipping by 7zip, the 7za utiliy is required on server.
Π£ΡΡΠ°Π½ΠΎΠ²ΠΊΠ°
ΠΡΠ΅Π΄ΠΏΠΎΡΡΠΈΡΠ΅Π»ΡΠ½ΡΠΌ ΡΠΏΠΎΡΠΎΠ±ΠΎΠΌ ΡΡΡΠ°Π½ΠΎΠ²ΠΊΠΈ ΡΠ²Π»ΡΠ΅ΡΡΡ ΠΏΡΠΈ ΠΏΠΎΠΌΠΎΡΠΈ composer., (*14)
ΠΠΈΠ±ΠΎ ΠΊΠΎΠΌΠ°Π½Π΄ΠΎΠΉ ΠΈΠ· ΠΊΠΎΠ½ΡΠΎΠ»ΠΈ, (*15)
php composer.phar require --prefer-dist victor78/yii2-zipper:"~0.0.4"
Π»ΠΈΠ±ΠΎ Π²ΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ΠΌ Π² composer.json Π² ΡΠ΅ΠΊΡΠΈΡ require., (*16)
"victor78/yii2-zipper": "~0.0.4"
ΠΠ°ΡΡΡΠΎΠΉΠΊΠ°
'type' ΠΈ 'password' - ΠΎΠΏΡΠΈΠΎΠ½Π°Π»ΡΠ½Ρ., (*17)
return [
//....
'components' => [
'zipper' => [
'class' => 'Victor78\Zipper\Zipper', //required
'type' => '7zip', //ΠΈΠ»ΠΈ: 'zip' (ΠΏΠΎ ΡΠΌΠΎΠ»ΡΠ°Π½ΠΈΡ), 'tar', 'tar.gz', 'tar.bz2'
'password' => 'password12345', //ΠΎΠΏΡΠΈΠΎΠ½Π°Π»ΡΠ½ΠΎ, ΡΠ°Π±ΠΎΡΠ°Π΅Ρ ΡΠΎΠ»ΡΠΊΠΎ ΠΏΡΠΈ ΡΠΈΠΏΠ΅ 7zip
],
]
];
ΠΠ°ΠΊ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ
ΠΠ»Ρ ΡΠΎΠ·Π΄Π°Π½ΠΈΡ Π°ΡΡ
ΠΈΠ²Π°:, (*18)
//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');
ΠΡΠΊΡΡΡΡ ΠΈ ΡΠ°ΡΠΏΠ°ΠΊΠΎΠ²Π°ΡΡ Π°ΡΡ
ΠΈΠ²:, (*19)
$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., (*20)
ΠΠ±Π° ΠΌΠ΅ΡΠΎΠ΄Π° Π²ΠΎΠ·Π²ΡΠ°ΡΠ°ΡΡ ΠΎΠ±ΡΠ΅ΠΊΡ Archive. ΠΡ ΠΌΠΎΠΆΠ΅ΡΠ΅ Π½Π°ΠΉΡΠΈ Π΄Π΅ΡΠ°Π»ΠΈ ΠΎ ΡΠΎΠΌ, ΠΊΠ°ΠΊ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ Π΄Π°Π½Π½ΡΠΉ ΠΎΠ±ΡΠ΅ΠΊΡ ΠΈ Π΄ΡΡΠ³ΡΡ ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΡ Π² Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ°ΡΠΈΠΈ ΠΊ Π±ΠΈΠ±Π»ΠΎΡΠ΅ΠΊΠ΅ ZippyExt., (*21)
Π’ΡΠ΅Π±ΠΎΠ²Π°Π½ΠΈΡ
- ΠΠ»Ρ Π°ΡΡ
ΠΈΠ²ΠΈΡΠΎΠ²Π°Π½ΠΈΡ Π² ΡΠΈΡΡΡΠΉ zip ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΡΡΡ ΡΡΠΈΠ»ΠΈΡΠ° zip ΠΈΠ»ΠΈ ΡΠ°ΡΡΠΈΡΠ΅Π½ΠΈΠ΅ PHP Π΄Π»Ρ zip, ΡΠ°ΠΊ ΡΡΠΎ ΠΈΠ»ΠΈ ΡΡΠΈΠ»ΠΈΡΠ°, ΠΈΠ»ΠΈ ΡΠ°ΡΡΠΈΡΠ΅Π½ΠΈΠ΅ Π΄ΠΎΠ»ΠΆΠ½Ρ Π±ΡΡΡ ΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½Ρ Π½Π° ΡΠ΅ΡΠ²Π΅ΡΠ΅ Π΄Π»Ρ ΡΠΏΠ°Π²ΠΊΠΈ ΠΈ ΡΠ°Π·ΡΠΏΠ°ΠΊΠΎΠ²ΠΊΠΈ zip.
- ΠΠ»Ρ tar, tar.gz, tar.bz2 Zipper ΠΏΡΡΠ°Π΅ΡΡΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ GNU tar ΠΈΠ»ΠΈ BSD tar, ΠΎΠ΄ΠΈΠ½ ΠΈΠ· Π½ΠΈΡ
Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±ΡΡΡ ΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½ Π½Π° ΡΠ΅ΡΠ²Π΅ΡΠ΅ Π΄Π»Ρ ΡΡΠΈΡ
ΡΠΈΠΏΠΎΠ² Π°ΡΡ
ΠΈΠ²ΠΎΠ².
- ΠΠ»Ρ ΡΠΏΠ°ΠΊΠΎΠ²ΠΊΠΈ/ΡΠ°Π·ΡΠΏΠ°ΠΊΠΎΠ²ΠΊΠΈ zip ΠΏΡΠΈ ΠΏΠΎΠΌΠΎΡΠΈ 7zip, Π½Π° ΡΠ΅ΡΠ²Π΅ΡΠ΅ Π΄ΠΎΠ»ΠΆΠ° Π±ΡΡΡ ΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½Π° ΡΡΠΈΠ»ΠΈΡΠ° 7za.