[英]How do I make a file downloadable in laravel?
我需要前端帮助
以下是我如何将文件发送到刀片
$files = Storage::disk('local')->allFiles('init/'.$id);
return view('view_name',['files'=>$files]);
以下是我在前端处理的方式
@foreach($files as $file)
<a href="{{ \Illuminate\Support\Facades\Storage::url(basename($file)) }}" download>{{basename($file) }}</a>
@endforeach
当我单击链接时,我看到“失败 - 无文件”错误。
我从这几天开始尝试这个,它似乎被卡住了。 请建议。
您可以将文件地址保存在数据库中并使用以下代码: $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);
}
下载方法可用于生成强制用户浏览器在给定路径下载文件的响应
return Storage::download('file.jpg');
return Storage::download('file.jpg', $name, $headers);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.