Latest web development tutorials

PHP chmod () function

PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual

Definition and Usage

chmod () function to change the permissions of the specified file.

If successful it returns TRUE, on failure returns FALSE.

grammar

chmod(file,mode)

参数 描述
file 必需。规定要检查的文件。
mode 必需。规定新的权限。

mode 参数由 4 个数字组成:

  • 第一个数字通常是 0
  • 第二个数字规定所有者的权限
  • 第三个数字规定所有者所属的用户组的权限
  • 第四个数字规定其他所有人的权限

可能的值(如需设置多个权限,请对下面的数字进行总计):

  • 1 = 执行权限
  • 2 = 写权限
  • 4 = 读权限


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 Reference Manual Complete PHP Filesystem Reference Manual