View Full Version : php apache file ownership and creation problem

04-04-2011, 06:25 PM
I am trying to do a really basic rename of a file to another name in my code. However there seems to be some ownership/permissions problem that is stopping this working correctly.

This is my (simplified) code:

ini_set ("display_errors", "1");

$St_Num = '7940';
$Co_Code = 'RDCO2';

rename("$St_Num-$Co_Code-1.jpg", "$St_Num-$Co_Code-4.jpg");

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.


04-05-2011, 03:21 AM
Who was the original owner of the file(s) in question? I'm thinking that file permissions are probably for all users to have read access only and only the file owner (apache) to have write access. You will have to change the file permissions to allow all users to write the file, from the console it would be something like chmod a+w ./<filename> .

However that would be a bad idea since that would make it so that anyone to write to the file not just your intended user. Why do the files need to be owned by the apache user?