我有此文件夾結構:-類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貢獻1780條經驗 獲得超5個贊
我認為您提供了錯誤的路徑,請嘗試此
$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貢獻1813條經驗 獲得超2個贊
您可能需要從Tasks.php向上查找一個目錄,使用:
public function __construct($user_id)
{
$this->userdata = json_decode(file_get_contents(__DIR__.'/../configs/tasks.json'), true);
}

翻翻過去那場雪
TA貢獻2065條經驗 獲得超14個贊
嘗試:
$this->userdata = json_decode(file_get_contents('../configs/tasks.json'), true);
- 3 回答
- 0 關注
- 221 瀏覽
添加回答
舉報
0/150
提交
取消