Page 1 of 1

CHMOD problem

Posted: Wed Jan 27, 2010 1:10 pm
by Think Pink
Hello.
Please advice.

I have an upload script that should upload an image on a server.
The problem is that it returns the following error:
chmod() [function.chmod]: Not owner in /w...............
I use CHMOD($folder, 0777)

This application runs without a problem on many other servers, except on this one.
safe_mode is off, so CHMOD is not disabled by safe_mode

Thankyou for your help

Re: CHMOD problem

Posted: Wed Jan 27, 2010 2:14 pm
by AbraCadaver
If the webserver user doesn't own the directory then chmod won't work. You need to chmod it from the command line as the owner, or as the owner chown it to the webserver user.

Re: CHMOD problem

Posted: Wed Jan 27, 2010 2:20 pm
by Think Pink
Yes, I know that CHMOD it won't work.
How can I CHOWN it? I mean how do I find the webserver user?

Re: CHMOD problem

Posted: Wed Jan 27, 2010 2:26 pm
by AbraCadaver
Think Pink wrote:Yes, I know that CHMOD it won't work.
How can I CHOWN it? I mean how do I find the webserver user?
Depends on your os and web server. I have Apache 2.2 on Ubuntu:

Code: Select all

shawn@shawn-laptop:~$ ps -ef|grep apache
Gives me:

Code: Select all

root      4047 16879  0 Jan24 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  4053 16879  0 Jan24 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  4054 16879  0 Jan24 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  4055 16879  0 Jan24 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  4056 16879  0 Jan24 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  4057 16879  0 Jan24 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  8795 16879  0 Jan26 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  8798 16879  0 Jan26 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  8802 16879  0 Jan26 ?        00:00:00 /usr/sbin/apache2 -k start
root     16879     1  0 Jan23 ?        00:00:04 /usr/sbin/apache2 -k start
So the www-user is running Apache. You'll need to be root or the owner of the directory in order to chown it.

Re: CHMOD problem

Posted: Wed Jan 27, 2010 3:31 pm
by Think Pink
Thx for your reply.
You'll need to be root or the owner of the directory in order to chown it.
Sorry, but I know that. The problem is that I don't have access on the server. So I can't run commands. I mean, I develop, and then I send the files to someone else and he uploads. I keep telling them that would be much easier if I would have access or know the settings, or ...or ...or, but is not possible. Looks like they have paranoic settings.
So the idea is to create some more test files.

Code: Select all

// File name and username to use
$file_name= "winter.txt";
$paths = "/home/xxxx/public_html/yyy/zzz/" . $file_name ;
 
// Check the result
$stat = stat($paths);
$array = posix_getpwuid($stat['uid']);
$uid = $array['uid'];
 
// Set the user
chown($paths, intval($uid));
 
chmod ($paths, octdec($mode));
Any ideea if this might work? because I am sick of always sending them a file, upload it, then run some tests, then the feedback back to me.

Re: CHMOD problem

Posted: Wed Jan 27, 2010 3:51 pm
by AbraCadaver
No, because the web server user is not root and not the owner of that dir or it would already be able to write to it. Have the admin chmod or chown it or you're out of luck.