php - Laravel - 保存在存储文件夹中的图像未向用户显示
问题描述
我有这段代码可以将图像保存在 storage/app/uploads 文件夹中
$image_main = Image::where('property_id', $id)->get();
$file = $request->file('file');
$destinationPath = 'uploads';
$i = 0;
foreach ($file as $file1) {
$i++;
$extension = $file1->getClientOriginalExtension();
$path = $file1->storeAs(
$destinationPath, $i.time().".".$extension
);
这是我的刀片文件
@foreach ($image_main as $images)
<img src="{{"/storage/app/".$images->filename}}
该文件保存在 storage/app/uploads 文件夹中,但它不会向用户显示,它说找不到文件。我要在 filesystems.php 文件中设置什么吗
解决方案
Laravel 存储文件系统是如此独特。当您进行任何上传时,它将上传到storage/app/public
目录中。要使其在public
目录中可访问,需要做的是通过运行命令创建符号链接:
php artisan storage:link
此命令将符号链接storage/app/public
到public/storage
只需按照有关如何放置和如何检索文件 url 的文档。我很确定您缺少的步骤是创建符号链接。
希望能帮助到你。
推荐阅读
- c++ - C++ - 在子字符串上执行的查找函数不起作用
- html - 在 Django 模板中多次使用相同的标签包装内容
- c# - C# 模拟一个函数
- google-cloud-sql - Cloud SQL 实例卡在“更新”上
- php - PHP:获取 MAC 地址
- sql - 重复使用相同的查询,但只更新嵌套变量的值
- javascript - Jquery:Ajax 调用不起作用
- jquery - 谁能向我解释一下 jquery document.ready() life-circle 是如何工作的
- r - R根据不同列中范围内的值添加新列
- c++ - CreateEnclave VBS 尝试访问无效地址