PHP code example of originphp / zip

1. Go to this page and download the library: Download originphp/zip 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/ */

    

originphp / zip example snippets


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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