php文件t.php放在目录(绝对路径)/usr/local/www/wxtest <?php header("Content-type: text/html; charset=utf-8"); $fp=fopen('txt/test.txt', 'wb'); if($fp) fwrite($fp, "TESTSETST"); else echo "fail to create file. <br/>"; fclose($fp); ?>在windows浏览器地址直接输入该php文件 执行结果如下: Warning: fopen(txt/test.txt): failed to open stream: Permission denied in /usr/local/www/wxtest/t.php on line 87 fail to create file. Warning: fclose() expects parameter 1 to be resource, boolean given in /usr/local/www/wxtest/t.php on line 90
echo substr(sprintf('%o', fileperms('你的目录')), -4); //看看是什么结果
比如 /home/centos/123.txt
目录home、centos也都是需要写的权限的不只是单单123.txt需要写权限
请贴出
<?php header("Content-type: text/html; charset=utf-8");
$fp=fopen('txt/test.txt', 'wb');
if($fp) fwrite($fp, "TESTSETST");
else echo "fail to create file. <br/>";
fclose($fp);
?>在windows浏览器地址直接输入该php文件
执行结果如下:
Warning: fopen(txt/test.txt): failed to open stream: Permission denied in /usr/local/www/wxtest/t.php on line 87 fail to create file.
Warning: fclose() expects parameter 1 to be resource, boolean given in /usr/local/www/wxtest/t.php on line 90
Permission denied
拒绝访问
请检查目录存在且可写
并且防止上级目录权限不足,我把/usr/local/www/wxtest/txt所有目录都设置成了755,都包含写权限,还是不行。
组外用户不就是other组吗?你指的是什么?
查看SELinux状态:
1、/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态
SELinux status: enabled
2、getenforce ##也可以用这个命令检查
关闭SELinux:
1、临时关闭(不用重启机器):
setenforce 0 ##设置SELinux 成为permissive模式
##setenforce 1 设置SELinux 成为enforcing模式
2、修改配置文件需要重启机器:
修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled
重启机器即可另外,如果以上还是不能解决的话要设置一下目录的权限策略
chcon -R -t httpd_sys_content_t /home/html