note 34345 added to function.chmod

From: Date: Thu, 24 Jul 2003 12:21:39 +0000
Subject: note 34345 added to function.chmod
Groups: php.notes 
Request: Send a blank email to php-notes+get-52554@lists.php.net to get a copy of this message
To let users manipulate their file rights (via PHP fs interface) you can call a shell_exec()/system() however, it doesn't get any more ugly then that. The problem, chmod only want's (int) as mode type. However PHP converts: 0755 to it's octal value (493) and if you force to stay int, the value becomes: 755. This fails: <? chmod("fubar.txt", "0". 755); chmod("fubar.txt", "0755"); chmod("fubar.txt", 755); ?> The work-around: <? $chmod = "0755"; # File mode $file = "fubar.txt"; # file // Create test file (if it doesn't exists) touch($file); // setting chmod eval("chmod(\"". $file ."\", ". $chmod .");"); // Showing current permissions echo "permissions: ". sprintf("%o", fileperms($file)); // Output: permissions: 100755 (which is: (7)rwx (5)r-x (5)r-x) ?> ---- Manual Page -- http://www.php.net/manual/en/function.chmod.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34345 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34345&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34345&report=yes

« previous php.notes (#52554) next »