dongqin1075 2011-11-11 08:05
浏览 196
已采纳

在php中更改目录权限(chmod)

I have googled but I can't seem to get my script to work.

this is my code

if (is_dir("tmp")) {
    if (substr(sprintf("%o", fileperms("tmp")), -4) == "0777") {
        echo "good";
    } else {
        echo "going to chmod the tmp folder to 777";
        if (!chmod("tmp", octdec(0777))) { // tried chmod("tmp, 0777) too
                echo "Oops, I couldn't chmod the /setup/tmp directory, please do this manually";
        }
    }
} else {
    echo "we'll make the folder";
}

I can't seem to get the chmod to work, i read somewhere that if register globals was off then this wouldn't work(i have that setting set to off).

I followed the PHP.net manual and some of the examples they provided there in the user comments, as well as some stack-overflow posts that i found relevant. but perhaps i need to tweak some php settings to get this to work?

Is there a way to get the chmod function to work without needing to change the PHP.ini?

  • 写回答

3条回答 默认 最新

  • dpzjl68484 2011-11-11 08:14
    关注

    You haven't given us enough information to determine why chmod() is failing. It could be that the web-server doesn't have sufficient privileges to alter directory permissions.

    The owner of the web-server process should own the directory or be a member of the owning group. For example, if root owns tmp, and your web-server is running as the user 'apache', it will not be possible to modify the directory's permissions from PHP.

    I believe the settings you mention in php.ini are for debugging, not magically 'fixing' chmod. Try prepending the following lines of code to your PHP script and you should get more useful debug output:

    ini_set('display_errors', 'On');
    error_reporting(E_ALL)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?