doukun0888 2019-01-18 09:17
浏览 47

如何在laravel刀片中显示存储图像?

I have stored my image with following code

if (isset($image)) {
    // make unique name for image
    $currentDate = Carbon::now()->toDateString();
    $imagename = $slug . '-' . $currentDate . '-' . uniqid() . '.' . $image->getClientOriginalExtension();

    // check category dir is exists
    if (!Storage::disk('public')->exists('category')) {
        Storage::disk('public')->makeDirectory('category');
    }
    // resize image for category and upload
    $category = Image::make($image)->resize(1600,479)->stream();
    Storage::disk('public')->put('category/'.$imagename,$category);
    // check category slider dir is exists
    if (!Storage::disk('public')->exists('category/slider')) {
        Storage::disk('public')->makeDirectory('category/slider');
    }
    // resize image for category slider and upload
    $slider = Image::make($image)->resize(500,333)->stream();
    Storage::disk('public')->put('category/slider/'.$imagename,$slider);
} else {
    $imagename = "default.png";
}

try with this code

<img src="images/icons8-team-355979.jpg" alt="Profile Image">

Failed to load resource: the server responded with a status of 404 (Not Found) this is the error

  • 写回答

2条回答 默认 最新

  • duangu4980 2019-01-18 09:21
    关注

    Try this

    <img src="{{url('category/slider')}}/{{ $category->image }}" alt="{{$category->name}}">
    

    The url function will go to '/public' folder. So, you may need to edit your '/config/filesystem.php' so that the uploaded photo is saved inside the '/public' directory.

    For more information on this please check this document.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用