Laravel 5 多重下载文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36675505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 Multiple Download File
提问by Thailand Love U
This code will work correctly if I open browser at 127.0.0.1/load/files. (Auto Download File)
如果我在 127.0.0.1/load/files 打开浏览器,此代码将正常工作。(自动下载文件)
ABCController.php
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
我可以使用 1 个路径和 1 个功能同时下载 2 个文件吗?如
function download_file(){
return Response::download(["file_1.txt","file_2.txt"]); //this code not right
}
Thank you for any help.
感谢您的任何帮助。
采纳答案by Elias
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.
使用 HTTP 协议通过同一个请求同时发送多个文件是不可能的。Laravel 也不支持这一点。例如,您必须将文件打包成 zip 文件。
Also see
另见
- download multiple files as zip in php
- Zipper(a handy wrapper for ZipArchive)
- 在php中以zip格式下载多个文件
- 拉链(一个方便的 ZipArchive 包装器)
回答by Borna
It is possibleto download multiple files in Laravel even without a zip option using the jQuery promise()Method.
即使没有使用 jQuery promise()方法的 zip 选项,也可以在 Laravel 中下载多个文件。
For details solution description (example+audio), go this following link
有关详细解决方案说明(示例+音频),请转到以下链接
https://www.youtube.com/watch?v=IA03QeE59Fk
https://www.youtube.com/watch?v=IA03QeE59Fk
For project link https://gitlab.com/Bons/download-multi-files-in-laravel-without-zip-option
对于项目链接 https://gitlab.com/Bons/download-multi-files-in-laravel-without-zip-option