我有此文件夹结构:-类Tasks.php-配置task.json我需要从classes文件夹中获取文件数据task.json public function __construct($user_id) { $this->userdata = json_decode(file_get_contents('.\configs\tasks.json'), true); }我试图指出另一种路径(通过完整路径)作为响应,我得到一个空数组或警告:file_get_contents(/configs/tasks.json):无法打开流:在...中没有这样的文件或目录
3 回答

蓝山帝景
TA贡献1843条经验 获得超7个赞
您可能需要从Tasks.php向上查找一个目录,使用:
public function __construct($user_id)
{
$this->userdata = json_decode(file_get_contents(__DIR__.'/../configs/tasks.json'), true);
}

蛊毒传说
TA贡献1895条经验 获得超3个赞
我认为您提供了错误的路径,请尝试此
$this->userdata = json_decode(file_get_contents(__DIR__.'/configs/tasks.json'), true);
如果您的PHP文件位于类dir中,请使用
$this->userdata = json_decode(file_get_contents(__DIR__.'/../configs/tasks.json'), true);

繁星淼淼
TA贡献1775条经验 获得超11个赞
尝试:
$this->userdata = json_decode(file_get_contents('../configs/tasks.json'), true);
- 3 回答
- 0 关注
- 136 浏览
添加回答
举报
0/150
提交
取消