chmod in PHP

Syntax of chmod in PHP

bool chmod(string path, int mode)

Attempts to change the permissions of path to mode. mode is expected to be an octal number, such as 0755. An integer value such as 755 or a string value such as “u+x” will not work as expected. Returns true if the operation was successful and false if not

Example of chmod

chmod(“/somedir/somefile”, 755);   // decimal; probably incorrect
chmod(“/somedir/somefile”, “u+rwx,go+rx”); // string; incorrect
chmod(“/somedir/somefile”, 0755);  // octal; correct value of mode

Leave a Comment