繁体   English   中英

在Laravel中使用store()上传文件后未找到404错误

[英]Not Found 404 error after file upload using store() in Laravel

我已经在Laravel 5.8中使用以下代码上传了图像, 图像上传正常 但是当我尝试显示它时,它给出了404错误。

public function store(ImageUpload $request)
{    
    $path = $request->file('image')->store('public/user_images');
    echo "<img src='" . $path . "'>";
}

我还尝试了<img src=".asset($path).">它也给出了404 Not Found错误。 可能是什么原因呢?

您可以使用以下网址

Storage::url($path);

返回的$path实际上是内部存储中服务器上的路径,而不是文件的URL。

使用storage:link您基本上是从http://url.dev/storage/链接到/storage/public

https://laravel.com/docs/5.8/filesystem#file-urls

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM