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 5.7 Image Upload with Validation Example
- Laravel 5.7 get ip address
- Email Verification in laravel 5.7 Example
- Calculate age from date of birth in Laravel
- Get date on change event of Bootstrap Datepicker
- PHP Laravel 7.x and 6.x Union query Example