4

This code will work correctly if I open browser at 127.0.0.1/load/files. (Auto Download File)

ABCController.php

namespace App\Http\Controllers;

use Response;
use File;

function download_file(){
    return Response::download(public_path() . "/files/file_1.txt");
}

routes.php

Route::get('/load/files','ABCController@download_file');

Can I use 1 route and 1 function for download 2 files at the same time ? Such as

function download_file(){
    return Response::download(["file_1.txt","file_2.txt"]); //this code not right
}

Thank you for any help.

Thailand Love U
  • 79
  • 1
  • 1
  • 7

3 Answers3

2

It is not possible to send more than one file simultaneously over the same request with the HTTP protocol. Laravel also does not support this. You have to pack the files in, for example, a zip file.

Also see

Elias
  • 1,532
  • 8
  • 19
  • 1
    I would not say that it is completely impossible (though it's correct for one request). I think at something like popping up two browser windows each starting a download. But it's not worth the problems and packing the files is a good solution. – Paul Spiegel Apr 17 '16 at 12:15
  • Google and Flickr both offer a way to download multiple files at once. I'm still not sure how they manage to do it. Google will queue up 4 at a time. If I remember correctly. – tlorens Oct 05 '20 at 02:48
2

Another alternative is to add 2 iFrames, this worked for me, So as per your example..

<iframe id="iframe_1" style="display:none;" src="/file_1.txt"></iframe>
<iframe id="iframe_2" style="display:none;" src="/file_2.txt"></iframe>

You will need to set seperate Routes and Controller methods of for file_1.txt & file_2.txt of course...

steve sonius
  • 398
  • 3
  • 11
1

It is possible to download multiple files in Laravel even without a zip option using the jQuery promise() Method.

For details solution description (example+audio), go this following link

https://www.youtube.com/watch?v=IA03QeE59Fk

For project link https://gitlab.com/Bons/download-multi-files-in-laravel-without-zip-option

Borna
  • 538
  • 4
  • 19