Laravel Multiple Files Download with Response Example
If you need to give to download multiple files response from out application. If you require to give download only on file then you can do it easily like this way:
return response()->download(public_path('myimage.jpg'));
But if you need to give multiple images files or docs etc then you can't do it this way:
return response()->download([public_path('myimage.jpg'),public_path('myimage2.jpg')]);
But you must have to create single zip file or something. So first you need to use zipper package, i added zipper package on my previous post you can install from here : Laravel 5 create and download zip file example using chumper/zipper composer package
Ok, now you can write controller method this way for download multifiles response:
Controller Method
public function donwloadMultipleFile()
{
Zipper::make('mydir/mytest12.zip')->add(['thumbnail/1461610581.jpg','thumbnail/1461610616.jpg']);
return response()->download(public_path('mydir/mytest12.zip'));
}
Try this way it can help you.......
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Order By Multiple Columns Example
- How to Automatically Generate Sitemap in Laravel?
- How to Install Bootstrap in Laravel?
- Laravel Fetch Data using Ajax Example
- How to Add Password Protection for PDF File in Laravel?
- How to Add Two Factor Authentication with SMS in Laravel?
- Laravel Get Next and Previous Record with URL Example
- Laravel Add Custom Configuration File Example
- Laravel Send SMS to Mobile with Nexmo Example
- Laravel Carbon Check If Date is Greater Than Other Date
- How to Insert Multiple Records in Laravel?
- How to Create Zip File in Laravel?
- Laravel 5.2 multi auth example using Auth guard from scratch
- Laravel Order By with Column Value Example