【问题标题】:Retrieving path error while displaying image from the Database in Laravel 6在 Laravel 6 中显示数据库中的图像时检索路径错误
【发布时间】:2020-06-06 14:49:37
【问题描述】:

我在显示数据库中的图像时遇到了错误。它显示一个路径错误,例如“没有配置驱动程序

.. Disk [uploads/] does not have a configured driver. (View: C:\xamppz\htdocs\webProject\resources\views\records.blade.php)

即使我在文件系统中配置了文件,它也显示错误。 帮我解决这个问题。

@foreach($blogs as $key => $blog)
<tr>
  <th scope="row"> {{ $blog->id}} </th> 
  <td> {{ $blog->first_name}} </td> 
  <td> {{ $blog->last_name}} </td> 
  <td> {{ $blog->email}} </td> 
  <td><img class="img-responsive thumbnail" src="{{ Storage::disk('uploads/'.$blog->image) }}" alt="image" width="50"> </td> 
  <td> {{ $blog->description}} </td> 
  <td> {{ $blog->created_at}} </td> 
  <td> {{ $blog->updated_at}} </td> 
</tr>
@endforeach
</tbody>

【问题讨论】:

标签: php mysql laravel localhost


【解决方案1】:

你可以这样使用

<img class="img-responsive thumbnail" src="{{ url('uploads/'.$blog->image) }}" alt="image" width="50">

【讨论】:

  • 感谢错误消失了。但是我看不到我上传的图像。默认图像图标在那里。如何查看我的实际图像?
【解决方案2】:

根据 Laravel 文档

当使用本地驱动时,所有的文件操作都是相对于 root 目录在您的 filesystems 配置文件中定义。经过 默认情况下,此值设置为storage/app 目录。

因此,默认情况下,您的代码会在 storage/app 中查找图像。您可以在filesystems 配置文件中配置您的映射,如下所示

'uploads' => [
    'driver' => 'local',
    'root' => storage_path('uploads'),
],

参考: Laravel -> File Storage -> The Local Driver

【讨论】:

    【解决方案3】:

    好吧,对于公共 url,您必须定义为公共驱动程序,也不是本地驱动程序。但是你应该考虑你的系统安全。

    【讨论】:

      猜你喜欢
      • 2018-10-27
      • 1970-01-01
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      • 1970-01-01
      • 2015-02-12
      相关资源
      最近更新 更多