Laravel 5 Multiple Download File

19,727

Solution 1

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

Solution 2

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

Solution 3

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...

Share:
19,727
Thailand Love U
Author by

Thailand Love U

Updated on June 04, 2022

Comments

  • Thailand Love U
    Thailand Love U almost 2 years

    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.

  • Paul Spiegel
    Paul Spiegel almost 8 years
    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.
  • tlorens
    tlorens over 3 years
    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.