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

 时间:2026-02-15 00:30:13

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)

  • linux系统中如何使用useradd命令添加用户?
  • Eclipse怎么集成Maven
  • python环境变量配置 如何设置?
  • eclipse如何设置字符串的查找范围
  • 制作notepad++代码的自动完成的功能如PHPJS等
  • 热门搜索
    是怎么回事 车前草怎么吃 建行怎么查开户行 孙悟空怎么画 dinner怎么读 芈月怎么读 茯苓怎么吃 飞机怎么折 皮蛋怎么做好吃 转账支票怎么填写