Are you want to create zip file programmatically in laravel application then chumper/zipper composer package is help to generate zip file simply. Sometime we need to create zip file with images or other files, then also you have to give download as response.
In this article i will let you know how to generate zip file and download as response in laravel 5.5 application using chumper/zipper composer package. you have to just follow few step to generate zip file in laravel 5.5 application.
Install chumper/zipper Package:
first thing is to install composer package in our project. so install chumper/zipper composer package by following composer command in your laravel 5.5 application.
composer require chumper/zipper
After successfully install package, open config/app.php file and add service provider and alias.
'providers' => [
'aliases' => [
'Zipper' => 'Chumper\Zipper\Zipper'
Now we will add route for demo example, so simply add following route in your route file, here we will add "downloadZip" route and you can download created zip file:
Create HomeController method:
Here, we require to create new controller HomeController that will manage index method of route. So let's put bellow code.
class HomeController extends Controller
* Create a new controller instance.
* @return void
$files = glob(public_path('css/*'));
You can simply run this example and check it.
I hope you found your best.
Do you like below Tutorials ?
- Laravel generate random unique string example
- Laravel - chmod(storage/oauth-private.key): Operation failed: Operation not permitted
- Laravel 7.x and 6.x datatables example from scratch
- How to compress PNG image using pngquant in PHP?
- Laravel 7.x and 6.x Chart example using Charts Package
- Guzzle http client GET and POST request example in Laravel 5
- Laravel schema default current timestamp value example
- Laravel 7.x and 6.x Get Site URL Examples