Download the PHP package selective/zip-responder without Composer
On this page you can find all versions of the php package selective/zip-responder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package zip-responder
selective/zip-responder
A ZIP responder (PSR-7).
Table of Contents
- Requirements
- Installation
- Usage
- Sending a ZIP file
- Sending a ZIP file from a string
- Sending a ZIP stream
- Sending a ZipArchive file
- Sending a ZipStream-PHP archive
- Sending a PhpZip archive
- Slim 4 Integration
Requirements
- PHP 7.3+ or 8.0+
- A PSR-7 StreamFactory implementation, e.g. nyholm/psr7
Installation
Usage
Creating a new ZipResponder instance using the nyholm/psr7
Psr17Factory:
Creating a new ZipResponder instance using the slim/psr7
StreamFactory:
Sending a ZIP file
Send ZIP file to browser, force direct download:
Sending a ZIP file from a string
Sending a ZIP stream
Send ZIP stream to the browser, force direct download:
Sending a ZIP stream on the fly
Sending a file directly to the client is not intended according to the PSR-7 specification, but can still be realized with the help of a CallbackStream.
Sending a ZipArchive file
The ZIP extension enables you to transparently read or write ZIP compressed archives and the files inside them. A ZipArchive does not support "memory mapped files", like PHP streams. You can only access local files with ZipArchive. For this purpose, you can create a temporary file, or you can use an existing file from the filesystem.
Sending a ZipStream-PHP archive
ZipStream-PHP is a library for streaming dynamic ZIP files without writing to the disk. You can send the file directly to the user, which is much faster and improves testability.
Installation:
Creating and sending a ZIP file (only in-memory) to the browser:
Sending a ZIP-stream on the fly:
Sending a PhpZip archive
PhpZip is a library for extended work with ZIP-archives.
Installation:
Note, when you use the nelexa/zip
component, you may not need the selective/zip-responder
component because the nelexa/zip
already provides its own PSR-7 responder.
Example
In case you want to keep your architecture more clean (SRP),
you may use the selective/zip-responder
responder to create
and send a ZIP file to the browser as follows:
Slim 4 Integration
Create a DI container definition for: StreamFactoryInterface::class
and ZipResponder::class
A nyholm/psr7
and PHP-DI example:
A slim/psr7
and PHP-DI example:
The responder should only be used within an action handler or middleware.
Action class example using dependency injection:
License
The MIT License (MIT). Please see License File for more information.