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

2024-11-08 10:47:25

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)

猜你喜欢