how to make a zip file from a folder and download it in Laravel step by step. In this php laravel application, we will produce a zip file by utilizing the zip-archive class.
Lets demonstrate how to implement a very simple zip file method in a Laravel application. So let's see a few items steps and consider them as an example. I will show you two method.
Fist Method which is using ZipArchive Class
- Setup Laravel
- The same as with route above, we will add one new route method here. downloadZipFile() will build a new zip file and download it as a response, so Please add this line.
NOTE : Make sure you have myFolder in your public path/directory.
Now run your project with this command
php artisan serve
to start developement server.Now please go the route like
http://127.0.0.1:8000/download-zip-file
from your browser, it will make the folder zip and download automatically.
Second Method : Using open-source Laravel Zip Package
- We are keeping same route to make it quick
- Go to controoller and just follow this
downloadZipFile
method.
NOTE : Make sure you have myFolder in your public path/directory.
- Now run your project with this command
php artisan serve
to start developement server again.Go the route, thats will create zip folder at your public path.
From avobe two method i personally prefer 2nd one. Cause thats easy to handle and quick. hope both method is working, if not please feel free to comment.
Read my others post
Dont forget to comment if need any help