首页 > 解决方案 > Laravel - 保存在存储文件夹中的图像未向用户显示

问题描述

我有这段代码可以将图像保存在 storage/app/uploads 文件夹中

 $image_main = Image::where('property_id', $id)->get();

$file = $request->file('file');
      $destinationPath = 'uploads';
      $i = 0;
      foreach ($file as $file1) {
          $i++;
          $extension = $file1->getClientOriginalExtension();
          $path = $file1->storeAs(
              $destinationPath, $i.time().".".$extension
          );

这是我的刀片文件

@foreach ($image_main as $images)
        <img src="{{"/storage/app/".$images->filename}}

该文件保存在 storage/app/uploads 文件夹中,但它不会向用户显示,它说找不到文件。我要在 filesystems.php 文件中设置什么吗

标签: phplaravellaravel-5

解决方案


Laravel 存储文件系统是如此独特。当您进行任何上传时,它将上传到storage/app/public目录中。要使其在public目录中可访问,需要做的是通过运行命令创建符号链接:

php artisan storage:link

此命令将符号链接storage/app/publicpublic/storage

只需按照有关如何放置和如何检索文件 url 的文档我很确定您缺少的步骤是创建符号链接。

希望能帮助到你。


推荐阅读