Hi,

I am setting up a cron using php.

I have a file which I want to update by doing file_put_contents() on it via cron and via web browser (manual).

everything via web brower works fine, but cron gives a "permission denied".

I am overwriting the file each time it gets updated.

How can I resolve the permission issue?

Thanks in advance.

Did you set your permissions on the file to 0777?

I do not know how to set it programmatically.

Setting it via FTP is useless because each update rewrites the permission.

by "update" I mean running file_put_contents() on the file using the web brower. with cron, nothing works because of the permission problem.

I think I understand the reason being each time file_put_contents() is used, the file is re-created and the owner changes.

currently what I do is to unlink() the file, and then file_put_contents() again. But I think this is quite ridiculous because I can unlink() but cannot overwrite? So, I would like to learn how to do it the proper way with permissions. Any advice?

Thanks.

What you should do is set the file inside a folder, set the permissions of the folder, and all content to 0777.
That way, every file that gets sent to that folder will have the correct permission.

What you should do is set the file inside a folder, set the permissions of the folder, and all content to 0777.
That way, every file that gets sent to that folder will have the correct permission.

Like I said, everytime the update takes place, the permission resets. So it doesn't work out. =(

This article has been dead for over six months. Start a new discussion instead.