2017-03-15 56 views
2

我有位於holiday/app/Console/Commands/myCommand.php用PHP文件:如何在Laravel應用程序中查找特定文件?

namespace Holiday\Console\Commands; 

$bob = file_get_contents('Storage/data/BE.json'); 

和它的作品。

然而,在holiday/app/Http/Controllers/holidayController.php我:

namespace Holiday\Http\Controllers; 

$bob = file_get_contents('Storage/data/BE.json'); 

,但我得到

file_get_contents(Holiday/Storage/data/BE.json): failed to open stream: 
No such file or directory 

有誰知道這是爲什麼?

回答

2

你應該總是使用傭工來獲得正確的路徑。在這裏,使用storage_path()幫手。例如:

file_get_contents(storage_path('data/BE.json')) 

這將創建到laravel_project/storage/data/BE.json文件的正確路徑。

相關問題