路径Exception中不存在Laravel File :: get()文件

时间:2016-07-30 16:11:23

标签: php laravel file-get-contents

我正在尝试使用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 if语句中的dd($path)

,这是非常奇怪的

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

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

我感到困惑

1 个答案:

答案 0 :(得分:3)

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,您应该做得很好。