php更改文件权限的方法:使用函数【chmod】将filename所指定文件的模式改成mode所给定的,代码为【chmod ( string $filename , int $mode ) : bool】。

php更改文件权限的方法:
chmod说明和语法
chmod会尝试将 filename 所指定文件的模式改成 mode 所给定的。
chmod ( string $filename , int $mode ) : bool
chmod参数
立即学习“PHP免费学习笔记(深入)”;
filename:文件的路径。
mode:
注意 mode 不会被自动当成八进制数值,而且也不能用字符串(例如 "g w")。要确保正确操作,需要给 mode 前面加上 0:
<?php
chmod("/somedir/somefile", 755); // 十进制数,可能不对
chmod("/somedir/somefile", "u rwx,go rx"); // 字符串,不对
chmod("/somedir/somefile", 0755); // 八进制数,正确的 mode 值
?>mode 参数包含三个八进制数按顺序分别指定了所有者、所有者所在的组以及所有人的访问限制。每一部分都可以通过加入所需的权限来计算出所要的权限。数字 1 表示使文件可执行,数字 2 表示使文件可写,数字 4 表示使文件可读。加入这些数字来制定所需要的权限。有关 UNIX 系统的文件权限可以阅读手册“man 1 chmod”和“man 2 chmod”。
<?php
// Read and write for owner, nothing for everybody else
chmod("/somedir/somefile", 0600);
// Read and write for owner, read for everybody else
chmod("/somedir/somefile", 0644);
// Everything for owner, read and execute for others
chmod("/somedir/somefile", 0755);
// Everything for owner, read and execute for owner's group
chmod("/somedir/somefile", 0750);
?>chmod返回值
成功时返回 TRUE, 或者在失败时返回 FALSE。
相关学习推荐:php编程(视频)
以上就是php如何更改文件权限的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号