php文件或目录权限检查的方法

2025-11-07 10:12:46

1、检测文件或目录是否存在

file_exists($file_path)函数,存在返回 true,否则返回 false

2、windows系统

检查目录读权限

$dir = @opendir($file_path);

readdir($dir);  //先打开目录,再读目录

3、检查目录写权限

在目录添加测试文件:$test_file = $file_path . '/test.txt';

$fp = @fopen($test_file, 'wb');

@fwrite($fp, 'directory access testing.')

4、检查文件读写权限

$fp = @fopen($file_path, 'rb');  //以读方式打开文件

$fp = @fopen($file_path, 'ab+');@fwrite($fp, '');  ////以写方式打开文件,再写数据

5、linux系统

is_readable($file_path)

is_writable($file_path)

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢