PHP fopen error-Unable to open stream


#1

In a PHP file, I am trying to make a JSON file using the fopen command.

<?php
 $id = mysqli_insert_id();
  fopen("/village/user_data/$id.json");
?>

I get the error message

Warning: fopen(/village/user_data/4.json): failed to open stream: No such file or directory in /home/ubuntu/workspace/village/php/server.php on line 60
Do I have to grant PHP access to create/write files, am I incorrectly using parent directory `/`?

#2

You have to set allow_url_fopen to 1 in the php.ini

ini_set(“allow_url_fopen”, 1);