【问题标题】:Laravel can't found a stored file 404 NOT FOUNDLaravel 找不到存储的文件 404 NOT FOUND
【发布时间】:2021-10-14 03:56:32
【问题描述】:

因为我还没有找到解决方案,所以再次发布。

Laravel 找不到文件 storage/app/public/upload 当我使用http://127.0.0.1:8000/storage/upload/The_fileName.x 我得到404 not found 我也试过http://127.0.0.1:8000/storage/app/public/upload/The_fileName.x

我该怎么办?

DocumentController

    public function store(Request $request)
{
    $request->validate([
        'doc' =>  "required",...
    ]);

    $document = new document();

    $file = $request->file('doc');
    $filename=time().'.'.$file->getClientOriginalExtension() ;

    // I've tried these too, one by one and still get the same error .
    //$file_path = public_path('public/upload');
    //$file->move($file_path, $filename);
    //Storage::disk('local')->put($file, $filename);
    //request('doc')->store('upload', 'public');
     
    $file->storeAs('public/upload', $filename);
    $document->doc = $request->input('doc', $filename);
    $document->candidate_id = $candidate_id;
    $document->save();

提前谢谢你

【问题讨论】:

  • 您当前存储在public/upload,因此URL 路径为http://127.0.0.1:8000/upload/The_fileName.xThe_fileName.x 在您的文件系统中的什么位置?
  • @aynber 127.0.0.1:8000/upload/The_fileName.x 也不起作用,文件在 (C:\Users\user\Documents\project\storage\app\public\upload)

标签: php laravel file upload laravel-8


【解决方案1】:

根据Laravel document File Storage,您需要在public/storage 创建一个指向storage/app/public 的符号链接,然后您可以使用http://127.0.0.1:8000/upload/The_fileName.x 访问该文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-07
    • 2018-11-13
    • 1970-01-01
    • 2022-11-29
    • 2023-04-04
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多