• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php在服务器下创建文件权限的有关问题

php 搞代码 3年前 (2022-01-23) 31次浏览 已收录 0个评论

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 赋予呢?

就好比你没有权限进国务院,那么你怎么装扮也是进不去的,除非你去找某个关系


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php在服务器下创建文件权限的有关问题
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址