These are my permissions of the files I am trying to change:
-rw-r--r-- 1 apache dev 4065 Oct 22 17:57 7940-RDCO2-3.jpg
-rw-r--r-- 1 apache dev 4276 Oct 28 09:39 7940-RDCO2-2.jpg
-rw-r--r-- 1 apache dev 4336 Oct 28 09:39 7940-RDCO2-1.jpg
This code was working, and it seemed to work when apache was the *creator* of the file. However, when I changed the ownership to 'apache' it stopped working. Does PHP/Apache have a concept of knowing who the creator of a file was? Would this stop a rename() from working?
I'm stumped with this one now - any help is appreciated.
In most typical web host environments, PHP runs as an Apache module, and thus your scripts are executed under the Apache user. So if the file is owned by some other user, such as your personal login/FTP account, PHP functions such as rename() will only work on files created by another non-Apache user (e.g. you) if the file permissions include read and write for all users (666 or 777 in Linux/UNIX terms, or possibly 664 or 774 if the file owner and Apache share a user group).
So, if a file is created by your PHP script, then it is owned by the Apache user and can by default be rename()'d by it, but if created by your login user or other non-Apache user, then you need to give it the necessary permissions before your PHP script can modify it (assuming again that the script is being executed by Apache as is typically -- but not always -- the case).
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation