I have a cronjob.php script which computes an array and saves it in a folder
www.mywebsite.com/resoucres/array.json
cronjob.php
$array = array();
// A lot of code
file_put_contents("array.json",json_encode($array));
When I execute the script I get the
file_put_contents(array.json): failed to open stream: Permission denied in /home/user/www/mywebsite.com/resoucres/cronjob.php
Now as suggested in file_put_contents permission denied one could simply give the folder resources
chmod 777. But isn't this a security risk?
Does this mean that other poeple can also write on the files in this directory? Is it possible to only give cronjob.php the rights to change the file array.json
, or do I actually need to move the folder to /www/resources/cronjob.php/
so it can have chmod 777 but since noone can access it, it is save?