How To Download Multiple Files with Response in Laravel?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this post i will show how to download multiple files with response in laravel? If we have to give allow to download multiple files with response from out application. If you need to give download only on file then we can do it very easily as like as this way:

return response()->download(public_path('myimage.jpg'));      

But if we need to give the multiple images files or docs etc then we can’t do it this way:

return response()->download([public_path('myimage.jpg'),public_path('myimage2.jpg')]);

But we must have to create the single zip file or something. So at first we need to use zipper package, i added the zipper package on my previous post you can install from here: Laravel Create and Download Zip File using chumper/zipper

Okay, now we can write the controller method on this way for download multiples 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'));      
}

Read Also: Generate Captcha code and Validation by using BotDetect package in laravel

Thanks for read. I hope it help you. For more you can follow us on facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →