Wordpress - 创建Json文件

I am having a problem while creating a json file using a wordpress plugin created by me. My code consists of reading data from my database, putting it in an array and than storing it as a json file.

I've tried to change the path of my json file to my desktop folder and it worked. I have tried to create a file using pure php on the same directory. And it worked also.

This is my code:

$fp = fopen('C:\Users\Home\Desktopesults.json', 'w+');
fwrite($fp, json_encode($response[0]));
fclose($fp);

i think i have found the solution . it seems like wordpress has a problem with relative and absolute paths so to avoid problems it is better to use the wordpress function plugin_dir_path( FILE ) wich will return the path to your plugin file(php file ) as a string . and than concatenate it with the rest of you path and that's it it works . and it's adaptative .(on linux it will returns linux path format and same as windows )