我有此文件夾結(jié)構(gòu):-類Tasks.php-配置task.json我需要從classes文件夾中獲取文件數(shù)據(jù)task.json public function __construct($user_id) { $this->userdata = json_decode(file_get_contents('.\configs\tasks.json'), true); }我試圖指出另一種路徑(通過完整路徑)作為響應(yīng),我得到一個(gè)空數(shù)組或警告:file_get_contents(/configs/tasks.json):無法打開流:在...中沒有這樣的文件或目錄
3 回答

翻閱古今
TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊
我認(rèn)為您提供了錯(cuò)誤的路徑,請嘗試此
$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);

慕姐8265434
TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
您可能需要從Tasks.php向上查找一個(gè)目錄,使用:
public function __construct($user_id)
{
$this->userdata = json_decode(file_get_contents(__DIR__.'/../configs/tasks.json'), true);
}

翻翻過去那場雪
TA貢獻(xiàn)2065條經(jīng)驗(yàn) 獲得超14個(gè)贊
嘗試:
$this->userdata = json_decode(file_get_contents('../configs/tasks.json'), true);
- 3 回答
- 0 關(guān)注
- 225 瀏覽
添加回答
舉報(bào)
0/150
提交
取消