【发布时间】:2021-08-10 08:28:24
【问题描述】:
我只是一个初学者,我需要你的帮助。 编辑:即使我搜索 http://127.0.0.1:8000/storage/uploaded/the_filename 我得到 404 no found
我已经用过 php artisan storage:link
当我使用 <iframe src="/storage/uploaded/{{$data->doc}}"> 时出现错误 404 Not Found。
即使我写了<iframe src="/storage/uploaded/1628544440.docx">,我仍然得到404 Not Found。 1628544440.docx 是 DB 和 uploaded 文件夹中的文件名。
文件夹/storage/app/public/uploaded中的文档与数据库中的documents->doc同名。
我可以在代码中更改什么?
在DocumentController:
public function store(Request $request)
{
$request->validate([
'doc' => 'required',...
]);
$document = new document();
$file = $request->file('doc');
$filename = time().'.'.$file->getClientOriginalExtension() ;
$file->storeAs('uploaded', $filename);
$document->doc = $request->input('doc', $filename);
$document->candidate_id = $candidate_id;
$document->save();
}
public function show($id)
{
// to select a document that belongs to a candidate
$doc_id = DB::table('documents')
->select('id')
->where('candidate_id', $id)
->first()
->id;
$data = document::find($doc_id);
return view('candidate.document', compact('data'));
}
在candidate/document.blade.php:
<iframe src="/storage/uploaded/{{ $data->doc }}"></iframe>
提前谢谢你。
【问题讨论】:
-
存储在根目录吗?您可能想为当前目录尝试
./storage。 -
向我们展示您的文件/文件夹树。文件路径错误。
-
@infinitezero 不是它不在根目录中
-
/指向根目录./指向当前目录,../反向指向父目录。
标签: php laravel file laravel-8