1. Go to this page and download the library: Download motekar/laravel-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/ */
motekar / laravel-zip example snippets
use Motekar\LaravelZip\Facades\Zip;
Zip::make(storage_path('images.zip'))
->add(glob(storage_path('images/*')))
->close();
use Motekar\LaravelZip\Facades\Zip;
use Motekar\LaravelZip\ZipManager;
// Create a zip file and add files
$zip = Zip::make('test.zip')
->folder('test')
->add('composer.json');
// Add a file with a specific name
$zip = Zip::make('test.zip')
->folder('test')
->add('composer.json', 'test');
// Remove a file from the archive
$zip->remove('composer.lock');
// Add multiple files to a specific folder
$zip->folder('mySuperPackage')->add([
'vendor',
'composer.json'
]);
// Get file content from the archive
$content = $zip->getFileContent('mySuperPackage/composer.json');
// Extract specific files using whitelist
$zip->make('test.zip')
->extractTo('', ['mySuperPackage/composer.json'], ZipManager::WHITELIST)
->close();
// Get all .log files
$logFiles = Zip::make('test.zip')->listFiles('/\.log$/i');
// Get all non-.log files
$notLogFiles = Zip::make('test.zip')->listFiles('/^(?!.*\.log).*$/i');
use Motekar\LaravelZip\Facades\Zip;
use Motekar\LaravelZip\ZipManager;
// Whitelist example
Zip::make('test.zip')
->extractTo('public', ['vendor'], ZipManager::WHITELIST);
// Blacklist example
Zip::make('test.zip')
->extractTo('public', ['vendor'], ZipManager::BLACKLIST);
// Exact match example
Zip::make('test.zip')
->folder('vendor')
->extractTo('public', ['composer', 'bin/phpunit'], ZipManager::WHITELIST | ZipManager::EXACT_MATCH);