php create folder owner/group

4.3k Views Asked by At

I'd transfer my site to linux hosting, Its has an issue on uploading image to the system's auto create folder which permission is chmod 0777, I found that its always make the uploading failed because of owner/group is in www-data, how could it change owner/group to 'root' in order to upload the image into the folder?

$media_path = "../upload/".$nextid;

if(file_exists($media_path)){
//do nuthing

}else{

mkdir($media_path, 0777);
chmod($media_path, 0777);
chown($media_path, "root");
chgrp($media_path, "root");

}

Please advice. Thanks.

1

There are 1 best solutions below

1
On

You cannot use chown unless you are root. But creating the folders with 0777 is sufficient to allow anyone to write to them.