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?
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.
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>');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With