league/flysystem-ziparchive
Flysystem ZipArchive adapter sub-split. Use it to work with ZIP files via Flysystem’s filesystem abstraction. This repo is read-only for packaging; file issues and pull requests on the main Flysystem project: https://github.com/thephpleague/flysystem
League\Flysystem\Filesystem (via Storage facade), enabling consistent API for local, cloud, and now ZIP-based storage.config/filesystems.php), reducing boilerplate for ZIP-specific logic.local, s3) for hybrid workflows (e.g., "stream from S3, package into ZIP for download").ZipArchive (bundled with PHP) and Flysystem.filesystems.php:
'disks' => [
'zip_archive' => [
'driver' => 'ziparchive',
'path' => storage_path('app/archives'),
'url' => env('APP_URL').'/storage/archives',
],
],
ZipArchive edge cases (e.g., file permissions, large files).ZipArchive's in-memory operations.ZipArchive relies on PHP’s native extension; misconfigurations (e.g., open_basedir) can cause failures.ZipStream alternative) or async processing.Content-Disposition headers and virus-scanning if applicable.Storage::disk('zip_archive')->put() for seamless integration with existing file operations.storage events (e.g., Creating, Deleting) to hook into ZIP lifecycle (e.g., logging, notifications).php artisan zip:create).ZipArchive is CPU-intensive).composer.json:
composer require league/flysystem-ziparchive
filesystems.php.ZipArchive instantiation) with Flysystem calls.// Before
$zip = new ZipArchive();
$zip->open('archive.zip', ZipArchive::CREATE);
$zip->addFile('file.txt');
$zip->close();
// After
Storage::disk('zip_archive')->put('archive.zip', function ($contents) {
$zip = new ZipArchive();
$zip->open($contents, ZipArchive::CREATE);
$zip->addFile(public_path('file.txt'));
return $zip->close();
});
ZipArchive usage).ZipArchive is enabled (php -m | grep zip).path in filesystems.php.$this->app->bind('ziparchive', function () {
return new \League\Flysystem\ZipArchive\ZipArchiveAdapter(storage_path('app/archives'));
});
ZipService class to encapsulate business logic (e.g., "package user files into ZIP")./download-zip/{user_id}).ZipArchive for breaking changes (e.g., PHP 9.0 deprecations).league/flysystem-ziparchive if forks introduce fixes (check GitHub issues)..env.ZipArchive alternatives (e.g., ZipStream) if PHP adds native streaming support.ZipArchive errors (e.g., ZipArchive::ERRNO_* constants) for troubleshooting.Visibility and VisibilityNotSupported exceptions for permission issues.storage_path('app/archives') is writable.memory_limit or implement chunked writes.Str::slug()).memory_limit and max_execution_time for large ZIPs.ZipArchive instantiation overhead.ZipArchive operations; consider native extensions like php-zip (if available).| Failure Scenario | Impact | Mitigation |
|---|---|---|
ZipArchive extension disabled |
ZIP operations fail silently | Validate extension in bootstrap/app.php; add runtime check. |
| Out-of-memory on large ZIP | PHP crashes or timeouts | Implement chunked streaming; set memory_limit dynamically. |
| Concurrent ZIP writes | Corrupted archives |
How can I help you explore Laravel packages today?