Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP & Permissions

I have an application that I am transferring to a new server. In doing so the upload feature for customers accounts stopped working because the owner of the folders was 'ftp' and not 'apache' I solved it by renaming the folder and then using a directory copy function that I copied and pasted from somewhere in to a new folder with the correct name and it was all cool after that.

My question is this, can php change the ownership of a folder or files?

like image 416
Andrew Myers Avatar asked Oct 29 '25 05:10

Andrew Myers


2 Answers

Yeah, php can change ownership of a file. Use chown($file, $user). You could write a simple recursive script to change owner for each file using chown.

like image 50
Cyclone Avatar answered Oct 30 '25 21:10

Cyclone


Yes, as far as the user under which it runs has the permissions to do that.

You could use the chown function or wrap the shell command in an exec call to do it recursively with no need to program that as in

exec('chown -R user <your-dir>');
like image 44
Fabio Avatar answered Oct 30 '25 23:10

Fabio