note 34345 deleted from function.chmod by nlopess

From: Date: Fri, 26 Dec 2003 19:34:37 +0000
Subject: note 34345 deleted from function.chmod by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-62518@lists.php.net to get a copy of this message
Note Submitter: dynom [a] dynom * nl ---- 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) ?>

« previous php.notes (#62518) next »