Php Laravel 5多个下载文件

Php Laravel 5多个下载文件,php,laravel,laravel-5,laravel-routing,Php,Laravel,Laravel 5,Laravel Routing,如果我在127.0.0.1/load/files打开浏览器,此代码将正常工作。 (自动下载文件) ABCController.php namespace App\Http\Controllers; use Response; use File; function download_file(){ return Response::download(public_path() . "/files/file_1.txt"); } Route::get('/load/files','AB

如果我在127.0.0.1/load/files打开浏览器,此代码将正常工作。 (自动下载文件)

ABCController.php

namespace App\Http\Controllers;

use Response;
use File;

function download_file(){
    return Response::download(public_path() . "/files/file_1.txt");
}
Route::get('/load/files','ABCController@download_file');
routes.php

namespace App\Http\Controllers;

use Response;
use File;

function download_file(){
    return Response::download(public_path() . "/files/file_1.txt");
}
Route::get('/load/files','ABCController@download_file');
我可以使用1个路由和1个功能同时下载2个文件吗?比如

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

感谢您的帮助。

使用HTTP协议,在同一请求上不可能同时发送多个文件。拉威尔也不支持这一点。您必须将文件打包,例如,压缩文件

也看到

  • (方便的ZipArchive包装)

使用jQuerypromise()方法,即使没有zip选项,也可以在Laravel中下载多个文件

有关解决方案说明(示例+音频)的详细信息,请转到以下链接

项目链接

另一种选择是添加2个iFrame,这对我很有效, 所以根据你的例子

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


您需要为file_1.txt和file_2.txt设置单独的路由和控制器方法当然…

谢谢您的帮助。我现在将使用zip进行我的工作。我不会说这是完全不可能的(尽管对于一个请求它是正确的)。我想是在弹出两个浏览器窗口开始下载的时候。但是这些问题不值得,打包文件是一个很好的解决方案。谷歌和Flickr都提供了一种同时下载多个文件的方法。我还不知道他们是怎么做到的。谷歌将一次排队4人。如果我没记错的话,你有没有在网页上看到过这种行为?