定义

chmod()函数更改指定文件的权限。

 

语法

PHP chmod()函数具有以下语法。

chmod(file,mode)

 

参数

参数 是否必须 描述
file 需要。 要检查的文件
mode 需要。 新权限。

mode参数由四个数字组成:

  • 第一个数字始终为零
  • 第二个数字指定所有者的权限
  • 第三个数字指定所有者的用户组的权限
  • 第四个数字指定其他人的权限

可能的值(要设置多个权限,请添加以下数字):

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

 

返回值

成功时返回TRUE,失败时返回FALSE。

 

实例

<?php
/*
http://www.manongjc.com/article/1763.html
作者:码农教程
*/
//sets the file to readable, writable, and executable by all users
chmod(\"/var/www/myfile.txt\", 0777);

//sets the file to readable, writable, and executable by owner, 
//and just readable and writable by everyone else.

chmod(\"/var/www/myfile.txt\", 0755);

// 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 for owner\'s group
chmod(\"test.txt\",0740);

?>
收藏 打印