CHMOD problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

CHMOD problem

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: CHMOD problem

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

Re: CHMOD problem

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: CHMOD problem

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

Re: CHMOD problem

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: CHMOD problem

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply