0
我在下载存储文件夹中的文件时遇到问题。我没有收到错误消息。发生的只是重定向到404页面。该文件存在于给定的路径中,所以我很难过。我试图从响应()的第二个参数中删除$文档,但没有奏效。我需要做什么?奇怪的是,在本地主机上运行它的作品?Laravel下载文件问题
public function download(Request $request, $document)
{
$pathToFile = storage_path() . '/' . 'app/documents/client'.'/'.$document;
if (file_exists($pathToFile))
{
return response()->download($pathToFile, $document);
}
else
{
// Error
return redirect('errors.404');
}
}
文件系统
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
路线:
Route::get('documents/client/{document}', '[email protected]')->name('client.docs');
记录你的'$ pathToFile',看它是否真的存在,以及权限是什么。 – aynber
检查文件是否存在于正确的位置? –
该文件存在。但是这个路线是否正确?更新问题 –