Laravel - allow to download files from a folder in blade view

I'm stuck somewhere in the middle and I can't go on. Have folder, in folder files. In blade.view wants them download via link.

$fileNameGlob = glob($directory."*.*", GLOB_BRACE);

dd($fileNameGlob) return array

array:3 [▼
  0 => "/var/www/html/domain/storage/app/apiFiles/611106/extract/1.png"
  1 => "/var/www/html/domain/storage/app/apiFiles/611106/extract/2.png"
  2 => "/var/www/html/domain/storage/app/apiFiles/611106/extract/3.jpg"
  ]

when i try return response()->download($fileNameGlob) have problem with array. If i have file path how continue to download file ?

1 answer

  • answered 2020-10-29 19:29 Flo Espen

    Do you want to provide one link to download all files? Then you should zip the files beforehand and then deliver the zipfile path. You could also use:

    return response->download('apiFiles/611106/extract/1.png');                 
    return response()->download('apiFiles/611106/extract/1.png', $name, $headers); 
    

    But this would not work for the array, but for the single elements, so you should provide something like $fileNameGlob[i].