在路径中找不到 Laravel 文件,但它确实存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44769693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel File not found at path but it does exist
提问by kjdion84
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
[League\Flysystem\FileNotFoundException] 在路径找不到文件: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.
当我在资源管理器中复制并粘贴该确切路径时,它可以很好地打开 json 文件。
Here is my code:
这是我的代码:
$this->json = json_encode(Storage::get(resource_path('generate/json/'.$this->argument('model').'.json')));
采纳答案by kjdion84
I figured it out.
我想到了。
Storage::get
actually uses the path relative to the filesystem disk configuration, therefore the error message itself is misleading.
Storage::get
实际上使用相对于文件系统磁盘配置的路径,因此错误消息本身具有误导性。
I've corrected the issue by simply using file_get_contents()
instead.
我已经通过简单地使用file_get_contents()
来纠正了这个问题。
回答by Gluten
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
):
正如其他人指出的那样,Storage::get
确实使用了相对于文件系统磁盘配置的路径,默认情况下使用local
驱动程序 ( 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:
因此,如果您正在使用local
驱动程序并且您的文件驻留在app/public/yourfile.ext
例如,那么调用Storage
应该是:
Storage::get('public/yourfile.ext');
回答by Manish Champaneri
Try this
尝试这个
$this->json = json_encode(app_path('/resources/generate/json/Car.json');