Search code examples
phplaravelzip

I want to download multiple files from my storage folder in Laravel


hy developers, i want to download multiple files as a zip, but i keep getting errors

below is the code i have tried

   public function multiple($id){
$files = documents::where('claim_id', $id)->get();

 if ($files != '') {
       $filepath = storage_path('app/Documents/');
 foreach($files as $file) {

 $zipper = new \Chumper\Zipper\Zipper;
  $fi = storage_path('app/Documents/'.$file->file_name);
  $zipper->make($filepath.'doc.zip');
    } 
    return response()->download($filepath.'doc.zip');
 }
 else{
    Alert::info('Info', 'No Documents Available');
       return redirect()->back();
 }
} 

attached is the error i get

Error i get


Solution

  • Looks like you didn't add any files to your Zip.

    I think:

    $zipper->make($filepath.'doc.zip');
    

    Should be:

    $zipper->make($filepath.'doc.zip')->add($fi)->close();
    

    Make sure the files and zip are in the storage folder.