php在服务器上创建文件权限的问题
- PHP code
<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$res = fopen('/usr/local/asg/configs/meet.conf','a+');fclose($res);
在本地机上如果meet.conf文件不存在,则可以创建,但在服务器上不行,用ls命令看了下,没有可写的权限,于是,在代码中加了判断
- PHP code
<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->if(!is_writable('/usr/local/asg/configs')) { system('chmod 777 /usr/l<p>4本文¥来源gao!%daima.com搞$代*!码$网9</p><pre>搞代gaodaima码
ocal/asg/configs’);}$res = fopen(‘/usr/local/asg/configs/meet.conf’,’a+’);fclose($res);
运行后,依旧创建不了,再次改进了下
- PHP code
<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->if(!is_writable('/usr/local/asg/configs')) { system('chmod 777 /usr/local/asg/configs');}system('touch /usr/local/asg/configs/meet.conf');
运行了下,仍旧不行,再次变通,用putty登陆到服务器,用命令行进入该目录,直接用touch创建,我叉,有用了,为什么在php文件里运行会不成功呢???
——解决方案——————–
我认为你可以用php函数chmod 去完成这个操作
另外,要赋予php运行帐户有这个目录权限
——解决方案——————–
if (!is_dir(‘/usr/local/asg/configs’)) {
mkdir(‘/usr/local/asg/configs’);
chmod(‘/usr/local/asg/configs’,0777);
}
——解决方案——————–
对于 php 没有权限的目录,怎么能用 php 赋予呢?
就好比你没有权限进国务院,那么你怎么装扮也是进不去的,除非你去找某个关系