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

时间:2022-01-03 06:59:26

Storage/app/public-->This is my storage path of an images.

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

Controller code:

控制器代码:

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());
}

This is the way I'm storing the images into storage path of laravel(ie. Storage/app/public).The storage done successfully here.

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

View Code:

查看代码:

 @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

Here I am trying to display the stored image.But nothing displays there.

在这里,我试图显示存储的图像。但没有任何显示。

3 个解决方案

#1


1  

First make sure you have linked the storage/app/public to public/storage.

首先确保已将存储/应用/公共链接到公共/存储。

If not run php artisan storage:link

如果没有运行php artisan storage:link

Then in your view use Storage::url('public/' . $cdetail->image) to get the link.

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

#2


1  

Use asset() function like

使用asset()函数就好

example in your blade template: {{ asset('storage/app/public/'.$cdetail->image ) }}

您的刀片模板中的示例:{{asset('storage / app / public /'.$ cdetail-> image)}}

In case if you want to access in your controller asset('storage/app/public/'.$cdetail->image );

如果您想访问您的控制器资产('storage / app / public /'.$ cdetail-> image);

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

#3


-1  

I think you can tr this may be its help for you :

我想你可以这可能对你有所帮助:

<img src="{{ storage_path('app/public/$cdetail->
              image') }}"  width="50" height="50"></img>

Hope this work for you !!!

希望这对你有用!!!

#1


1  

First make sure you have linked the storage/app/public to public/storage.

首先确保已将存储/应用/公共链接到公共/存储。

If not run php artisan storage:link

如果没有运行php artisan storage:link

Then in your view use Storage::url('public/' . $cdetail->image) to get the link.

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

#2


1  

Use asset() function like

使用asset()函数就好

example in your blade template: {{ asset('storage/app/public/'.$cdetail->image ) }}

您的刀片模板中的示例:{{asset('storage / app / public /'.$ cdetail-> image)}}

In case if you want to access in your controller asset('storage/app/public/'.$cdetail->image );

如果您想访问您的控制器资产('storage / app / public /'.$ cdetail-> image);

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

#3


-1  

I think you can tr this may be its help for you :

我想你可以这可能对你有所帮助:

<img src="{{ storage_path('app/public/$cdetail->
              image') }}"  width="50" height="50"></img>

Hope this work for you !!!

希望这对你有用!!!