Laravel File not found at path but it does exist

旧时模样 提交于 2020-01-14 08:46:12

问题


Getting the following error in console when attempting to get a files contents:

[League\Flysystem\FileNotFoundException] File not found at path: C:/wamp64/www/lion/resources/generate/json/Car.json

When I copy and paste that exact path in explorer it opens the json file fine.

Here is my code:

$this->json = json_encode(Storage::get(resource_path('generate/json/'.$this->argument('model').'.json')));

回答1:


I figured it out.

Storage::get actually uses the path relative to the filesystem disk configuration, therefore the error message itself is misleading.

I've corrected the issue by simply using file_get_contents() instead.




回答2:


As others pointed out Storage::get indeed uses the path relative to the filesystem disk configuration, by default the local driver is used (config/filesystems.php):

'local' => [
    'driver' => 'local',
    'root' => storage_path('app'),
],

So if you are using the local driver and your file resides at app/public/yourfile.ext for example then the call to Storage should be:

Storage::get('public/yourfile.ext');



回答3:


Try this

$this->json = json_encode(app_path('/resources/generate/json/Car.json');


来源:https://stackoverflow.com/questions/44769693/laravel-file-not-found-at-path-but-it-does-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!