gpt4 book ai didi

php - 如何检索laravel5.4存储文件夹中存储的图像?

转载 作者:行者123 更新时间:2023-11-29 10:40:12 25 4
gpt4 key购买 nike

Storage/app/public-->这是我的图片存储路径。

Controller 代码:

public function addDeviceCategory(Request $cform)
{

if (Input::hasFile('imagefile'))
{
$name = $this->getImageId().".".$cform->file('imagefile')-
>getClientOriginalExtension();

$image = $cform->file('imagefile');
$resize = Image::make($image)->resize(700, 300)->encode($cform-
>file('imagefile')->getClientOriginalExtension());
$hash = md5($resize->__toString());

$path = "public/" . $name;
Storage::put($path, $resize->__toString());

}
$validation1=deviceCategory::select('deviceCategoryName')-
>where("deviceCategoryName",$cform->deviceCategory)->first();

if(is_null($validation1))
{

$temp=new deviceCategory;

$temp->deviceCategoryId=$this->getDeviceCategoryId();
$temp->deviceCategoryName=$cform->input('deviceCategory');
$temp->subCategoryId=$cform->input('subCategory');
$temp->image=$name;

$temp->save();

return redirect('formAddDeviceCategory');
}

}

public function getImageId(){
return md5(uniqid().microtime());
}

这就是我将图像存储到laravel存储路径(即Storage/app/public)的方式。这里存储成功。

查看代码:

 @php 
$l=1
@endphp
@foreach($cdetails as $cdetail)
<tr>
<td>{{$l++}}</td>
<td>{{$cdetail->deviceCategoryId}}</td>
<td>{{$cdetail->categoryName}}</td>
<td>{{$cdetail->subCategoryName}}</td>
<td>{{$cdetail->deviceCategoryName}}</td>

**<td><img src="{{ asset('storage/app/public/$cdetail->
image') }}" width="50" height="50"></img></td>**
@endforeach

这里我尝试显示存储的图像。但那里没有显示任何内容。

最佳答案

首先确保您已将 storage/app/public 链接到 public/storage

如果没有运行php artisan storage:link

然后在您的 View 中使用 Storage::url('public/' . $cdetail->image) 获取链接。

关于php - 如何检索laravel5.4存储文件夹中存储的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45628823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com