[英]How do I make a file downloadable in laravel?
I need help on frontend我需要前端帮助
Following is how I am sending files to blade以下是我如何将文件发送到刀片
$files = Storage::disk('local')->allFiles('init/'.$id);
return view('view_name',['files'=>$files]);
Following is how I handling on frontend以下是我在前端处理的方式
@foreach($files as $file)
<a href="{{ \Illuminate\Support\Facades\Storage::url(basename($file)) }}" download>{{basename($file) }}</a>
@endforeach
when I click on the link I see "Failed - No file" error.当我单击链接时,我看到“失败 - 无文件”错误。
I am trying this from couple of days now, it seems am stuck.我从这几天开始尝试这个,它似乎被卡住了。 please suggest.
请建议。
You can Save file address in database and use this code: $id: , $file:您可以将文件地址保存在数据库中并使用以下代码: $id: , $file:
public function showFile($id,$file){
$user= auth()->user();
if(!$user->hasPermission($id))
return abort(403);
$file=str_replace(',','',$file);
return response()->download(storage_path('../../domains/SITE.com/secureUp/aDoc/'.$id.'/'.$file), null, [], null);
}
The download method may be used to generate a response that forces the user's browser to download the file at the given path下载方法可用于生成强制用户浏览器在给定路径下载文件的响应
return Storage::download('file.jpg');
return Storage::download('file.jpg', $name, $headers);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.