尝试 fread() json 文件时 filesize() return 0

filesize() return 0 while trying to fread() a json file

关于我的目标的详细信息:

I Wanted to combine a new Data comes from my mobile application with the data which is stored on a Json file and used that data to process user things but any data greater than 1KB starts the error .

错误代码:PHP Warning: fread(): Length parameter must be greater than 0

我确定文件大小不是 0,它是 4.89KB!

代码:

        $RawFile = fopen($FileName, "w+") or die("Unable to open file!");
         $IsiFile = fread($RawFile,filesize($FileName));
          $DataFile = json_decode($IsiFile, true);
           $DataPengguna = $DataFile[$UserID];
           $DataOverwrite = $DataPengguna . '' . $tulisan;
          $DataFile[$UserID] = $DataOverwrite;
         fwrite($RawFile, json_encode($DataFile));
        fclose($RawFile);

Json 文件的内容:Prnt.sc/r9hek8

我的代码中变量的平均值:

$IsiFile = The Json

$DataFile = I prefer Array to access the data

$DataPengguna = The user Data [Every user have their own UserID]

$DataOverwrite = Combine the old already stored data with the new data

Put it back on the array and do fwrite(), then closed the file

这是一个逻辑错误的地方:fopen($FileName, "w+")
"w+" 模式总是丢弃文件内容。只需使用 "r+" 模式,如果稍后需要写入文件,请使用 "w+" 模式重新打开它。