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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.