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

时间:2017-08-11 06:56:10

标签: php mysql laravel

存储/应用/公开 - >这是我的图片存储路径。

控制器代码:

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存储路径(即存储/应用程序/公共)的方式。存储在这里成功完成。

查看代码:

 @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

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

2 个答案:

答案 0 :(得分:1)

使用像

这样的asset()函数

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

如果您想在控制器中访问 asset('storage/app/public/'.$cdetail->image );

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

答案 1 :(得分:-1)

我认为你可以帮助你:

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

希望这对你有用!!!

相关问题