2017-03-15 11 views
2

私はholiday/app/Console/Commands/myCommand.phpにあるPHPファイルを持っている:Laravelアプリケーションで特定のファイルを見つける方法は?

namespace Holiday\Console\Commands; 

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

をし、それが動作します。

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 

を得る:

しかしholiday/app/Http/Controllers/holidayController.phpで私が持っていますか?

答えて

2

正しいパスを取得するには、常にヘルパーを使用する必要があります。ここでは、storage_path()ヘルパーを使用してください。例えば:

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

これはlaravel_project/storage/data/BE.jsonファイルへの正しいパスを作成します。

関連する問題