【问题标题】:How to get a file from laravel folder storage for a treatment如何从 laravel 文件夹存储中获取文件进行治疗
【发布时间】:2019-10-16 11:08:13
【问题描述】:

我将图像保存在 storage/app/public 中,并创建了指向 public/storage 的符号链接,该链接运行良好,但是当我尝试使用 Storage :: get ($path) 方法获取图像时,我收到了 FileNotFoundException .我想知道如何在我的代码中获取我的图像

 $fichier=Storage::get('storage/avatarDebutFemme.png');

Illuminate \ Contracts \ Filesystem \ FileNotFoundException storage/avatarDebutFemme.png

以前的例外情况

在路径中找不到文件:storage/avatarDebutFemme.png (0)

【问题讨论】:

    标签: laravel get filesystems storage


    【解决方案1】:

    要访问您的存储路径,您应该使用storage helper 获取路径:

    $fichier = Storage::get(storage_path('app/public/avatarDebutFemme.png'));
    

    会在你的 Laravel 项目的 storage/app/public 文件夹中获得一个名为 avatarDebutFemme.png 的文件。

    【讨论】:

    • $fichier = Storage::get(storage_path('app\avatarDebutFemme.png'));
    • 我照你说的做了,但没有成功
    • 您遇到什么错误?该栏应该是/ 而不是`\`
    • Illuminate \ Contracts \ Filesystem \ FileNotFoundException C:\wamp64\www\projetFE\storage\app/public/avatarDebutFemme.png 这是错误信息
    • 我不知道你在windows上,然后用'/'代替。
    【解决方案2】:

    关注,laravel 站点,它可以帮助您解决问题File Storage-Laravel

    【讨论】:

    • 我按照他们在这个网站上说的做了,但它不起作用
    【解决方案3】:

    经过测试和工作 storage_path() 使用绝对路径 您将需要创建符号链接

    php artisan storage:link
    

    查看img标签

    src="{{route('employee.get.image', $employee->id)}}"
    

    下面是函数

    $path = storage_path('app/public/'.$image_url);//this will load storage/app/public/
        if (!File::exists($path)) {
            $path = public_path('images/avatar.jpg');
        }
        $file = File::get($path);
        $type = File::mimeType($path);
    
        $response = Response::make($file, 200);
        $response->header("Content-Type",'image/jpeg');
    
        return $response;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-06
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      • 2020-04-01
      • 2022-11-17
      • 2020-11-10
      • 2021-09-25
      相关资源
      最近更新 更多