2016-07-30 61 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 –

相關問題