php is_writable失败的解决办法:1、打开命令窗口;2、执行“chcon -R -t httpd_sys_content_rw_t /var/www/html”即可。

本文操作环境:centos7系统、PHP7版,DELL G3电脑
如何解决php is_writable 失败问题?
具体问题描述:
PHP7 is_writable总是返回false!
立即学习“PHP免费学习笔记(深入)”;
我的服务器是centos 7 ,test.txt是我在 /var/www/html 上面新建的测试文件而已。
权限是766 1 root root test.txt
通过chmod修改了nobody 【因为php.net上面说这个函数,的web访问是使用nobody身份】
766 1 nobody root test.txt
<?php
$filename = 'test.txt';
if (is_writable($filename)) {
echo 'The file is writable';
} else {
echo 'The file is not writable';
}
?>最后结果是,在服务器上面的编译时可以写的,在web访问是不可以写。怎么办呢?

解决办法:
chcon -R -t httpd_sys_content_rw_t /var/www/html
推荐学习:《PHP视频教程》
以上就是如何解决php is_writable 失败问题的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号