Laravel-保存在存储文件夹中的图像未显示给用户 [英] Laravel - Image saved in storage folder not showing to user
本文介绍了Laravel-保存在存储文件夹中的图像未显示给用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码可以将图像保存在storage/app/uploads文件夹中
I have this code to save an image in the storage/app/uploads folder
$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文件中设置任何内容吗?
The file saves in the storage/app/uploads folder but it doesn't show to the user, it says file not found. am I to set anything in the filesystems.php file
推荐答案
用户无法访问您的存储文件夹.
Your storage folder is not accessible from user.
您必须通过 Storage :: url()方法:
Storage::url("/storage/app/{$images->filename}")
作为:
<img src="{{ Storage::url("/storage/app/{$images->filename}") }}" alt="{{ $images->filename }}" />
https://laravel.com/docs/master/filesystem#retrieving-files
这篇关于Laravel-保存在存储文件夹中的图像未显示给用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文