【问题标题】:Laravel File::get() File does not exist at path ExceptionLaravel File::get() 文件在路径异常中不存在
【发布时间】:2016-07-30 16:11:23
【问题描述】:

我正在尝试使用 Laravel 文件系统获取外部文件,但我不断收到 File does not exist at path 异常

这是我的代码

File::get('http://lorempixel.com/272/172');

被调用的 Laravel 函数

 public function get($path, $lock = false)
{
    if ($this->isFile($path)) {
        return $lock ? $this->sharedGet($path) : file_get_contents($path);
    }

    throw new FileNotFoundException("File does not exist at path {$path}");
}

我已经在我的服务器上测试了file_get_contents('http://lorempixel.com/272/172'),效果很好。

如果在我得到的 if 语句中执行dd($path),这很奇怪

"/home/vagrant/Code/test/storage/framework/sessions/fdb554540ba30a38464950b36908fa20e0ee94cc" 已返回

如果我在 if 语句之外执行 dd($path),我会得到 http://lorempixel.com/272/172 返回

我很困惑

【问题讨论】:

    标签: php laravel file-get-contents


    【解决方案1】:

    File::get 仅用于本地文件,在 4.1 之前的 laravel 版本中,您可以使用File::getRemote

    $content = File::getRemote("http://lorempixel.com/272/172");
    

    但它在 laravel 4.1 中被删除了。根据 laravel 的创建者 @taylorotwell 的说法,它是不安全的。它所做的只是调用file_get_contents,所以只需将其替换为file_get_contents,你应该会很好。

    【讨论】:

    • File::getRemote 在 5.1 中已被弃用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    • 2021-09-18
    • 1970-01-01
    • 2017-07-26
    • 2016-07-05
    • 1970-01-01
    相关资源
    最近更新 更多