PHP chmod()Functions


PHP Filesystem 参考手册Complete PHP Filesystem Reference Manual

Definition and Usage

The chmod() function changes permissions of the specified file.

Returns TRUE on success, or FALSE on failure.

Syntax

chmod(file,mode)

Parameters Description
file Required. Specifies the file to check.
mode Required. Specifies the new permissions.

The mode parameter consists of 4 numbers:

  • The first number is usually 0
  • The second number specifies the permissions for the owner
  • The third number specifies the permissions for the user group that the owner belongs to
  • The fourth number specifies the permissions for all others

Possible values (to set multiple permissions, add the numbers below):

  • 1 = execute permissions
  • 2 = write permissions
  • 4 = read permissions


Examples

<?php
// Read and write for owner, nothing for everybody else
chmod("test.txt",0600);

// Read and write for owner, read for everybody else
chmod("test.txt",0644);

// Everything for owner, read and execute for everybody else
chmod("test.txt",0755);

// Everything for owner, read for owner's group
chmod("test.txt",0740);
?>


PHP Filesystem 参考手册Complete PHP Filesystem Reference Manual Other Extensions