php - 在 laravel 5.2 的路径中找不到文件

标签 php laravel laravel-5

我在 public/badges 目录中有一个名为 1.png 的图像 - 我正在尝试在 laravel 中使用存储库,但即使该文件确实存在于该位置,也会不断收到以下错误:

//错误

FileNotFoundException in Filesystem.php line 381:
File not found at path: Users/gk/Sites/mysite/public/badges/1.png

//代码

$filePath = 'badges/1.png';
$path = public_path()."/".$filePath
Storage::disk('local')->get($path);
dd($contents);

最佳答案

形成 Laravel 5.2 文档:

When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory.

所以你正在寻找文件:storage/app/Users/gk/Sites/mysite/public/badges/1.png

错误很困惑。

[更新]

添加到 config/filesystems.php

'disks' => [

    //... 

    'local_public' => [
        'driver' => 'local',
        'root'   => public_path(),
    ],

    //... 
],

然后

$filePath = 'badges/1.png';
$content = Storage::disk('local_public')->get($filePath);
dd($content);

关于php - 在 laravel 5.2 的路径中找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37562850/

相关文章:

javascript - 在 Laravel 中从 Vue 检索文件

php - 如何将相关表中的值连接到 Laravel eloquent 集合?

php - laravel 5.4 ownsTo 和 hasMany 不适用于 2 个外键

php - 如何缩短函数查询?

php - php中基于正态分布的年龄匹配算法

php - 从 MySQL 将标签列表转换为结构化数组的最佳方法?

php - Laravel 5:在控制台内核的 Schedule() 函数中使用 Cache::or DB::

php - Laravel 路线未定义,但显然是

php - 我如何编译这个 CSS

php - 最低 varchar 数量