Apache server file permissions

259 views Asked by At

I know this was brought up many times. Still I can not find a sutable answer.

I want to upload a file to a server and want to set temporary 777 permission to the file where I put content. I am the only owner of the file and the directory and it does not seem to be an option to change or add an owner from the control panel and I dont want to set 777 to that folder. Since neither apache nor script own the file chmod does not work. Is there a way to get the ownership to php, a particular script or the server throught chown function? The script that POST a file is not publically accessible btw.

Thanks.

1

There are 1 answers

4
Devsome On

Dunno if I am right or not.
First you can get the owner of the file with this

$filename = 'index.php';
print_r(posix_getpwuid(fileowner($filename)));

with

chmod('/var/www/folder/', 0777)
chmod('/var/www/folder/index.php', 0777)

you can change any folder or file to 0777
you can also check with chmod the file or folder have

if( chmod($path, 0777) ) {
    chmod($path, 0755);
}