8.12.1 Setting permissions: chmod()This is NOT the latest copy of this book; click here for the latest version.
bool chmod ( string filename, int mode)
Note: this section applies only to those using PHP on a Unix-like operating system. The reason for this is because Windows has a vastly different security system to Unix, where privileges are handed out by user and user group. Whereas Unix users can say "read only for user, read-write for group", Windows users on Windows 95, 98, and ME can only say "read only" or "not read only". PHP does not support the fine-grained Windows NT/2000/XP/2003 access model.
If you are using a Unix box, you can use PHP's chmod() function like you would use chmod from the command line, with the difference that you need to precede the security level with a 0 to show that it is an octal value. Chmod() takes two parameters: the file to set, and the value to set it to. Here are two examples:
<?php
chmod("/var/www/myfile.txt", 0777);
chmod("/var/www/myfile.txt", 0755); ?>
Line one sets the file to readable, writeable, and executable by all users, whereas line two sets the file to readable, writeable, and executable by owner, and just readable and writeable by everyone else.
|
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.
My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!
|