为了账号安全,请及时绑定邮箱和手机立即绑定

其他文件夹中的file_get_contents

其他文件夹中的file_get_contents

PHP
倚天杖 2021-03-09 17:14:10
我有此文件夹结构:-类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);

}


查看完整回答
反对 回复 2021-04-23
?
蛊毒传说

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);



查看完整回答
反对 回复 2021-04-23
?
繁星淼淼

TA贡献1775条经验 获得超11个赞

尝试:

$this->userdata = json_decode(file_get_contents('../configs/tasks.json'), true);


查看完整回答
反对 回复 2021-04-23
  • 3 回答
  • 0 关注
  • 136 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号