Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

chmode problem !!

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
I tried to use the following code to chmode a directory in my linux box and in my internet host:

<?
$dir=&quot;/usr/local/apache/htdocs/myif( file_exists( $dir ) ){
if( !is_file( $dir ) ){
chmod($dir,0755);
}
}
?>

but I get the message:
Warning: chmod failed: Operation not permitted in /usr/local/apache/htdocs/my on line 5

I tried $dir=&quot;/usr/local/apache/htdocs/myAnd I get the same result. Any help?
Thanks in advance.
 
kubla,
Yes, chmod operates on files. But since everything is a file in the UNIX world, it also operates on devices and directories.

hisham,
Is the webserver user the owner of the file? You have to be the owner (maybe group works too, not really sure on this one) to use chmod and it's similar commands. //Daniel
 
Daniel,
I think so, because I can chmod it using ftp
 
Doing it via FTP is different to doing it by code, because they tend to have different permissions (don't know why, permissions aren't really my area)
 
The permission difference is because of who is performing the action.

In FTP, any action you take is based on the user as which you logged in.

In WWW, the script is run as the user the web daemon uses to operate. Permissions need to be relative to that user. Want the best answers? Ask the best questions: TANSTAAFL!
 
i tried with ftp using the following code:

$dir=&quot;my$cmd = &quot;chmod($dir, 0777)&quot;;
if ($login_result) {
@ftp_site ($conn_id, $cmd);
}

i didn't get error message, but the permission still 755
 
Correction. You're setting it to the value:
&quot;chmod (my 0777)&quot;

On PHP 4.3.0 running on Linux, the following code works

Code:
<?php

$mydir = 'myfoo/mybar';
$foo = @chmod ($mydir, 0777);
print ($foo === TRUE) ? &quot;worked&quot; : &quot;no joy&quot;;

?>

If and only if the user as which Apache runs is the owner of the directory. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top