【问题标题】:Can't display the uploaded image laravel无法显示上传的图片 laravel
【发布时间】:2020-12-19 17:36:41
【问题描述】:

我正在尝试上传图片以在视图中显示它,但是当我尝试显示它时,它不会显示在我视图的图像部分。

我已经有符号链接,它可以工作。我可以在“公共/存储/图像”路径中看到我上传的图像。 它还显示在 'storage\app\public\images' 路径上。

显示图片的代码

@if(filled($book->image))
<img src="{{asset($book->image)}}" style="width: 8%;height:8%">

我的图片上传代码

if ($request->hasFile('book_image')) {
    $book->image = $request->file('book_image')->storeAs('public/images', $request->id . '.' . $request->file('book_image')->getClientOriginalExtension());
}

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    使用src="{{ url('/images/'.$book-&gt;image) }}"

    【讨论】:

    • 写下你的图片完整路径
    【解决方案2】:

    如果您想在刀片中获取图像 url,那么您可以使用 url helper,例如 img src="{{ url('storage/app/public/images/'.$filename) }}"

    或其他类似的地方

    storage_path('/app/public/images/' . $filename)

    【讨论】:

      【解决方案3】:

      像这样重写你的代码

      <img src="{{asset('images/'.$book->image)}}" style="width:8%; height:8%">
      

      如果您已经在命令行中运行storage:link,这应该可以工作

      【讨论】:

        猜你喜欢
        • 2014-07-25
        • 1970-01-01
        • 1970-01-01
        • 2020-09-17
        • 2020-10-02
        • 1970-01-01
        • 2022-12-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多