Jump to content

PHP chown


FinalFrontier

Recommended Posts

Basically. when someone uploads a file to my private server, the file is owned by www-data. I am wanting to make it so the file is owned by me, and looking for a quick way to achieve it. I tried this, but its not working and I have no idea why:

 

<?php
$target_path = "/home/n/Miscellaneous/uploaded files/" . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
	basename($_FILES['file']['name']);
}
system('chown n /home/n/Miscellaneous/uploaded\ files/');
?>

 

Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/252444-php-chown/#findComment-1294291
Share on other sites

Only the superuser may change the owner of a file.  Your webserver is not the superuser (hopefully)

 

Perhaps you can just chmod the file so you have permission to use it.  Since the file is owned by the webserver, it can change the permissions of the file like:

 

chmod("/somedir/somefile", 666);

 

or whatever.  As it is your server, there are many other options from the system level as well.

 

Ref:

http://php.net/manual/en/function.chown.php

http://php.net/manual/en/function.chmod.php

Link to comment
https://forums.phpfreaks.com/topic/252444-php-chown/#findComment-1294353
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.