php chmod 权限无效,PHP无法chmod?

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

$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 '

';

print_r($result);

echo '

';

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/exist/的(子)文件夹都没有获得指定的(0777)权限?

解决方法:

在创建目录之前,您可能必须先清除umask.但是,建议使用chmod调整权限,而不是依赖于umask.

标签:php,ubuntu,unix,chmod,file-permissions

来源: https://codeday.me/bug/20190826/1734475.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值