PHP无法chmod? [英] PHP fails to chmod?

查看:107
本文介绍了PHP无法chmod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行PHP 5.3.5-1ubuntu7.2(其中 safe_mode = Off )并且我m无法从PHP脚本内正确设置任何文件或目录的模式,我对以下测试进行了编码(只是为了确保):

I'm running PHP 5.3.5-1ubuntu7.2 (with safe_mode = Off) and I'm unable to correctly set the mode for any file or directory from within a PHP script, I coded the following test (just to make sure):

$result = array();

if (mkdir('./I/do/not/exist/', 0777, true) === true)
{
    $result['./I/'] = sprintf('%s (%s)', getFileOwner('./I/'), getFilePermissions('./I/'));
    $result['./I/do/'] = sprintf('%s (%s)', getFileOwner('./I/do/'), getFilePermissions('./I/do/'));
    $result['./I/do/not/'] = sprintf('%s (%s)', getFileOwner('./I/do/not/'), getFilePermissions('./I/do/not/'));
    $result['./I/do/not/exist/'] = sprintf('%s (%s)', getFileOwner('./I/do/not/exist/'), getFilePermissions('./I/do/not/exist/'));
    $result[__DIR__] = sprintf('%s (%s)', getFileOwner(__DIR__), getFilePermissions(__DIR__));
    $result[__FILE__] = sprintf('%s (%s)', getFileOwner(__FILE__), getFilePermissions(__FILE__));
}

echo '<pre>';
print_r($result);
echo '</pre>';

function getFileOwner($path)
{
    $user = posix_getpwuid(fileowner($path));
    $group = posix_getgrgid(filegroup($path));

    return implode(':', array($user['name'], $group['name']));
}

function getFilePermissions($path)
{
    return substr(sprintf('%o', fileperms($path)), -4);
}

这是输出:

Array
(
    [./I/] => www-data:www-data (0755)
    [./I/do/] => www-data:www-data (0755)
    [./I/do/not/] => www-data:www-data (0755)
    [./I/do/not/exist/] => www-data:www-data (0755)
    [/home/alix/Server/_] => alix:alix (0777)
    [/home/alix/Server/_/chmod.php] => alix:alix (0644)
)

为什么的所有(子)文件夹都不起作用./I/do/not/不存在/ 不能得到指定的( 0777 )权限?

Why do none of the (sub-)folders of ./I/do/not/exist/ get the specified (0777) permissions?

推荐答案

您可能必须清除 umask 。但是,建议使用chmod调整权限,而不要依赖umask。

You may have to clear the umask first before creating the directory. However it is recommended to adjust the permissions using chmod instead of relying on umask.

这篇关于PHP无法chmod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆