Laravel 在路径中找不到文件但它确实存在
Laravel File not found at path but it does exist
尝试获取文件内容时在控制台中出现以下错误:
[League\Flysystem\FileNotFoundException] File not found at path:
C:/wamp64/www/lion/resources/generate/json/Car.json
当我在资源管理器中复制并粘贴该确切路径时,它可以正常打开 json 文件。
这是我的代码:
$this->json = json_encode(Storage::get(resource_path('generate/json/'.$this->argument('model').'.json')));
我想通了。
Storage::get
实际上使用了相对于文件系统磁盘配置的路径,因此错误消息本身具有误导性。
我已经通过简单地使用 file_get_contents()
来纠正这个问题。
试试这个
$this->json = json_encode(app_path('/resources/generate/json/Car.json');
正如其他人指出的那样 Storage::get
确实使用了相对于文件系统磁盘配置的路径,默认情况下使用 local
驱动程序 (config/filesystems.php
):
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
因此,如果您正在使用 local
驱动程序并且您的文件位于 app/public/yourfile.ext
,那么对 Storage
的调用应该是:
Storage::get('public/yourfile.ext');
尝试获取文件内容时在控制台中出现以下错误:
[League\Flysystem\FileNotFoundException] File not found at path: C:/wamp64/www/lion/resources/generate/json/Car.json
当我在资源管理器中复制并粘贴该确切路径时,它可以正常打开 json 文件。
这是我的代码:
$this->json = json_encode(Storage::get(resource_path('generate/json/'.$this->argument('model').'.json')));
我想通了。
Storage::get
实际上使用了相对于文件系统磁盘配置的路径,因此错误消息本身具有误导性。
我已经通过简单地使用 file_get_contents()
来纠正这个问题。
试试这个
$this->json = json_encode(app_path('/resources/generate/json/Car.json');
正如其他人指出的那样 Storage::get
确实使用了相对于文件系统磁盘配置的路径,默认情况下使用 local
驱动程序 (config/filesystems.php
):
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
因此,如果您正在使用 local
驱动程序并且您的文件位于 app/public/yourfile.ext
,那么对 Storage
的调用应该是:
Storage::get('public/yourfile.ext');