Page 1 of 1
CHMOD Problems...
Posted: Fri Aug 22, 2003 11:23 pm
by Mr. Tech
Hi!
I want to be able to chmod files online. I used:
chmod ("test.html", 0755); but it gives me this error:
Warning: chmod(): Operation not permitted in /home/uname/public_html/chmod.php on line 2
Do you know why this is happening?
Thanks

Posted: Sat Aug 23, 2003 12:27 am
by devork
better check whether you have rights to do that
check the rights for the dirctory too in which this file resides
Posted: Sat Aug 23, 2003 3:21 am
by Mr. Tech
What do you mean "rights"? The folder it is in needs to be writeable?
In my actual script the file I am chmoding in a parent folder... if that helps..
Thanks
Posted: Sat Aug 23, 2003 11:42 am
by McGruff
Mr. Tech wrote:What do you mean "rights"? The folder it is in needs to be writeable?
Files and folders permissions are stored for three user ids: owner, group and "anybody" - hence the three numbers eg 755.
Owner has 1 (read) + 2 (write) + 4 (execute) = 7
Group has 1 (read) + 4 (execute) = 5
Anybody has 1 (read + 4 (execute) = 5
Normally only the owner is granted full rwx permissions: 755 restricts other users. You can view owner/groups with your ftp program.
In many setups, files and folders created by php have php/php owner/group and so php would have rwx permissions with a 755 value.
If a file or folder was not created by php, it will not be owned by php, and hence php has the "anybody" permissions: r-x with 755.
Posted: Sun Aug 24, 2003 4:49 pm
by Mr. Tech
So php can only chmod the files/folders it created?
Bit confused...
Posted: Sun Aug 24, 2003 4:59 pm
by volka
more or less that's true.
it depends on the user id under which a file/directory has been created.
As McGruff pointed out, only the owner (and root) can change the permissons (wouldn't make too much sense otherwise, would it

).
Your php script runs under the permissons of a certain uid, unless configured otherwise that's the uid of the webserver. On unix-like systems that's often the user
nobody or
apache.
If you script creates a file/directory this uid is the owner and therefor can change the permission. If you create it via ftp with another uid (often according to your login) then php is not able the change the permissions.
Posted: Sun Aug 24, 2003 5:10 pm
by Mr. Tech
That is really stupid... Can I change pernissions...
Posted: Sun Aug 24, 2003 5:10 pm
by Mr. Tech
Sorry, I meant can I change the owner(user id)

Posted: Sun Aug 24, 2003 7:58 pm
by tsg
You can FTP to the server and change permissions to the folder.
Posted: Sun Aug 24, 2003 8:05 pm
by volka
with shell access and the system not configured to only allow root to change file ownership it's really simple.
and the whole directory together with its content and subdirectories belongs to
newowner.
But only few systems allow
SITE CHOWN for ftp and even less allow this to users other than root and only few and far between are those that will do it for a complete directory structure.
You could write a php-script that makes a deep copy of the directory.
And if you're lucky I'm all wrong and there is a much simpler solution

Posted: Sun Aug 24, 2003 9:18 pm
by Mr. Tech
There must be an easy way... Otherwise how would those file managers work?
I found this filemanager:
http://webmanager.sourceforge.net/
And it had a permission file... Maybe it will help:
Code: Select all
<?php
include("config.php");
include("func.php");
if (!isset($man_user)||(isset($man_user)&&$man_user==1))
{
include("login.php");
exit;
}
$ThisFileName = basename(__FILE__);
$root = str_replace($ThisFileName,"",__FILE__);
$root = dirname($root);
/////////////////////
//write = 2
//execute = 1
//read = 4
if (@$perms=="Set")
{
$own_exec=0;$own_read=0;$own_write=0;
$grp_exec=0;$grp_read=0;$grp_write=0;
$other_exec=0;$other_read=0;$other_write=0;
/////////////////////////////////////////////////////////////////////////////////
if (@$set_own_exec==true){$own_exec=1;}
if (@$set_own_read==true){$own_read=4;}
if (@$set_own_write==true){$own_write=2;}
/////////////////
if (@$set_grp_exec==true){$grp_exec=1;}
if (@$set_grp_read==true){$grp_read=4;}
if (@$set_grp_write==true){$grp_write=2;}
/////////////////
if (@$set_other_exec==true){$other_exec=1;}
if (@$set_other_read==true){$other_read=4;}
if (@$set_other_write==true){$other_write=2;}
/////////////////
$set_own=$own_exec+$own_read+$own_write;
$set_grp=$grp_exec+$grp_read+$grp_write;
$set_other=$other_exec+$other_read+$other_write;
////////////////////////////////////////////////////////////////////////////////
$chmode=$set_own.$set_grp.$set_other;
$buf=intval($chmode/100);
$buf1=$chmode-$buf*100;
$buf_0=intval($buf1/10);
$buf2=$buf1-$buf_0*10;
////////////////////////////////////////////////////////////////////////////////
if ($file_array[0]!="")
{
$dec1=1*32768+0*4096+0*512+$buf*64+$buf_0*8+$buf2*1;
for($a=0;$a<count($file_array);$a++)
{
if (@$folder)
{
$file=$root."/".$folder."/".basename($file_array[$a]);
}
else
{
$file=$root."/".$file_array[$a];
}
chmod($file, $dec1);
}
}
/////////////////////////////////
if ($folder_array[0]!="")
{
$dec2=4*4096+0*512+$buf*64+$buf_0*8+$buf2*1;
$dec1=1*32768+0*4096+0*512+$buf*64+$buf_0*8+$buf2*1;
for($a=0;$a<count($folder_array);$a++)
{
if (@$folder)
{
$file=$root."/".$folder."/".$folder_array[$a];
}
else
{
$file=$root."/".$folder_array[$a];
}
chmod($file, $dec2);
}
}
/////////////////////////////////
}
ret_head($folder);
?>
Posted: Mon Aug 25, 2003 7:27 am
by volka
still it needs the permission to change the file attributes.
If files are uploaded through the script (or one running as the same uid) it certainly has.