2016-07-30 53 views
-1

我试图使用Laravel文件系统获得相关的外部文件,但我不断收到一个File does not exist at path异常Laravel文件::得到()文件并不在路径异常存在

这里是我的代码

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')和工作正常。

如果做dd($path)的if语句中,我得到

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

如果我这样做dd($path) if语句之外,我得到http://lorempixel.com/272/172返回

我感到困惑,这是很奇怪的

回答

3

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

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

但它在laravel 4.1中被删除。根据laravel的创始人@泰勒洛特韦尔的说法,这是不安全的。它所做的只是拨打file_get_contents,所以只需将其替换为file_get_contents,你应该很好。

+0

File :: getRemote已在5.1中弃用 – user2834482

+0

请阅读https://github.com/laravel/framework/issues/3366 –

相关问题