dongshi4589 2014-11-06 17:59
浏览 77
已采纳

在PHP中将chmod设置为完整路径

I have input path: /var/www/site.com/1/2/3/4/file.php

I want to: set chmod 755 on each element after /var/www/site.com/

e.g. do that by universal algorithm:

chmod ('/var/www/site.com/1/', 0755);
chmod ('/var/www/site.com/1/2/', 0755);
chmod ('/var/www/site.com/1/2/3/', 0755);
chmod ('/var/www/site.com/1/2/3/4/', 0755);
chmod ('/var/www/site.com/1/2/3/4/file.php', 0755);

Can you help me, Please?

P.S.: Just only chmod full path, not recursive.

  • 写回答

1条回答 默认 最新

  • duandun2136 2014-11-06 18:16
    关注
    <?php
    function chmod_path($base, $path, $perm) {
        $full_path = $base;
        foreach (explode(DIRECTORY_SEPARATOR, $path) as $dentry) {
            $full_path .= DIRECTORY_SEPARATOR.$dentry;
            chmod($full_path, $perm);
        }
    }
    
    chmod_path('/var/www/site.com', '1/2/3/4/file.php', 0755);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?