Laravel存储无法访问 [英] Laravel storage can't be accessed
问题描述
我正在编写一个用于上传和显示一些图像的系统,但是我对上传后访问它们的正确方法感到困惑.
I am writing a system to upload and show some images, however I am confused about the correct way to access them once uploaded.
public function storeImage(Request $request)
{
$request->file('image')->store('public/images');
$filename = md5_file($request->file('image')) . '.' . $request->file('image')->extension();
$img = new Image;
$img->path = 'storage/images/'.$filename;
$img->save();
return back();
}
这正常工作,并且按照建议进行符号链接storage
,但是,如果我使用数据库中的$filename
变量,则会得到404.在此处生成作为内嵌图像src属性插入的正确路径是什么? ?
This works fine, and I have symlinked storage
as suggested, however if I use the $filename
variable from the database I get a 404. What is the correct path to generate to insert as an inline image src attribute here?
image标签如下所示:
<img src="storage/images/89cdd31f2e0eeacceff96c2a0abb252f.jpeg">
该文件夹肯定是符号链接的,因为我可以在finder中跟随它.
The image tag looks like this:
<img src="storage/images/89cdd31f2e0eeacceff96c2a0abb252f.jpeg">
The folder is definitely symlinked as I can follow it in finder.
推荐答案
已解决此问题.
php artisan storage:link
不适用于宅基.而是删除文件夹,使用homestead ssh
和ln -s ~/projects/my-website/storage/app/public/ ~/projects/my-website/public/storage
在计算机上手动重新创建它们.
php artisan storage:link
does not work with homestead. Instead delete the folder, manually recreate them on the machine using homestead ssh
and ln -s ~/projects/my-website/storage/app/public/ ~/projects/my-website/public/storage
.
这篇关于Laravel存储无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!