Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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 我在fopen中使用了错误的参数吗?_Php_Html_Ajax_Json_String - Fatal编程技术网

Php 我在fopen中使用了错误的参数吗?

Php 我在fopen中使用了错误的参数吗?,php,html,ajax,json,string,Php,Html,Ajax,Json,String,我将json值附加到外部文件。表单数据是通过ajax和post变量捕获的。我有一个小脚本,它会弹出JSON数据串,并试图将文件与中间变量(或实际上在结尾处)一起返回。 我将文件数据加载到$data中,并在文件字符串“]}的末尾将其分解。这样,它总是附加到结尾。但它不会爆炸/内爆给我带来问题。我可以使用str_替换并得到相同的结果。运行上面的PHP脚本后,我在data.json中得到了以下内容: {"uploads": [{"name":"foo","email":"foo@bar.com","i

我将json值附加到外部文件。表单数据是通过ajax和post变量捕获的。我有一个小脚本,它会弹出JSON数据串,并试图将文件与中间变量(或实际上在结尾处)一起返回。

我将文件数据加载到
$data
中,并在文件字符串“]}的末尾将其分解。这样,它总是附加到结尾。但它不会爆炸/内爆给我带来问题。我可以使用str_替换并得到相同的结果。运行上面的PHP脚本后,我在data.json中得到了以下内容:

{"uploads": [{"name":"foo","email":"foo@bar.com","imgurl":"http://placehold.it/50x50"}]}{"uploads": [{"name":"bar","email":"bar@foo.com","imgurl":"http://placehold.it/100x100"}]}   

我已经能够改变fopen的论点,得到不同的结果,但没有一个是我所希望的结果。有什么想法吗

您根本没有定义变量
$json
。PHP知道,
$json
为空。您的代码试图打开一个文件(用于读取),但该文件为空

有更好的存储数据的方法——如果MySQL太大太重,试试SQLite。像这样乱搞JSON只会让你头疼。
{"uploads": [{"name":"foo","email":"foo@bar.com","imgurl":"http://placehold.it/50x50"}]}
{"uploads": [{"name":"foo","email":"foo@bar.com","imgurl":"http://placehold.it/50x50"}]}{"uploads": [{"name":"bar","email":"bar@foo.com","imgurl":"http://placehold.it/100x100"}]}