laravel - 为什么我在尝试下载文件时出现此页面错误?
问题描述
嗨,我在尝试下载上传的文件时出错。我正在使用 laravel 7。错误是找不到 404 页面,可能是因为目录不匹配。
这是我的控制器中的存储方法:
public function store(Request $request){
$detalleTicket = new DetalleTicket();
if($request->file('file')){
$file = $request->file('file');
$filename = time().'.'.$file->getClientOriginalName();
$request->file->move('storage/', $filename);
$detalleTicket->file = $filename;
}
$detalleTicket->save();
Session::flash('success');
return redirect()->route('detalles-tickets.view');
}
这是我在控制器中的下载方法:
public function download($file){
return response()->download('storage/'.$file);
}
我的目录是 public->storage->(每个文件)
这是我在 web.php 中的路线:
Route::get('/download/{file}', 'Backend\DetalleTicketController@download')->name('detalles-tickets.download');
这是我的下载按钮:
<a title="Download" id="download" class="btn btn-sm btn-success"
href="/detalles-tickets/download/{{ $detalleTicket->file }}"><i
class="fa fa-download"></i></a>
有谁知道为什么单击按钮我找不到 404 页面?
解决方案
@if($detalleTicket->file)
<a
title="Download"
id="download"
class="btn btn-sm btn-success"
href="{{ route('detalles-tickets.download', ['file' => $detalleTicket->file]) }}">
<i class="fa fa-download"></i>
</a>
@endif
推荐阅读
- video - 带透明背面的视频
- python - 如何在跨越多行的文本中查找模式?
- blazor - 在 Blazor 服务器应用程序中检测服务器预渲染
- java - 无法在 Intellij IDEA 中创建 java 文件
- python - Pandas - 将函数应用于具有来自不同列的多个参数的数据框
- ios - 如何使用 SwiftDate 框架在当前时区打印日期和时间(本地化)
- c - 捕获 n 个子进程的退出代码
- sql-server - 列出在包含级别作为 SQL Server 中的属性的透视表中每个级别中存在的特定节点的所有祖先或父节点
- c++ - Cin/Cout 显示日期信息
- python - DRF ModelViewSet 查询集返回其日期大于或等于今天的结果