Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php file_get_contents():json文件的文件名不能为空_Php_Json - Fatal编程技术网

Php file_get_contents():json文件的文件名不能为空

Php file_get_contents():json文件的文件名不能为空,php,json,Php,Json,我有一个函数,应该将json文件作为数组返回,以便在其他地方进一步操作,但是我遇到了一个错误 文件\获取\内容():文件名不能为空 这是我的密码: function __getBlacklistAsArray__() { return file_get_contents( json_decode('config/list.json', true) ); } 提前谢谢 编辑1: 如果我从根目录中的文件调用相同的函数,它工作正常;如果我打印json\u decode(file\u ge

我有一个函数,应该将json文件作为数组返回,以便在其他地方进一步操作,但是我遇到了一个错误

文件\获取\内容():文件名不能为空

这是我的密码:

function __getBlacklistAsArray__() {

    return file_get_contents( json_decode('config/list.json', true) );
}
提前谢谢


编辑1:

如果我从根目录中的文件调用相同的函数,它工作正常;如果我打印
json\u decode(file\u get\u contents('config/list.json'),true)
它工作正常,并将显示json文件的内容

但是,如果我从根目录之外的另一个页面调用该函数,它会给出错误提示

文件\获取\内容(config/list.json):无法打开流:无此类 文件或目录


编辑2:

uVal.php

$accepted_domains = __getJSONArrayFromKey__('accepted_email_domains');
index.php

function __getJSONArrayFromKey__($str) {

    $arr = __getBlacklistAsArray__();

    if(isset($arr[$str])) {

        return $arr[$str];

    } else {

        return $str . " is not a valid key.";
    }
}
尝试:

json_decode(file_get_contents('config/list.json'), true);
它的工作原理应该是:

json_decode(file_get_contents('path/filename'), true);

如果您收到打开流失败的警告:没有这样的文件或目录,请检查您的文件路径或使用
\uuuuu file\uuuuu

我认为您需要使用不同顺序的json解码功能(file\u get\u contents('filePath'),true);你能分享一个触发错误的完整工作示例吗?可能的重复(重复是关于从不同的文件夹级别深度使用
include
,但你可以在这里对
file\u get\u contents
应用相同的内容)。路径错误
警告:file\u get\u contents(config/list.json):无法打开流:没有此类文件或目录
指向正确的文件名。。。在阅读之前,请检查文件是否存在(文件名)!
json_decode(file_get_contents('path/filename'), true);