gpt4 book ai didi

php - stat() 和符号运算符

转载 作者:可可西里 更新时间:2023-11-01 01:10:39 25 4
gpt4 key购买 nike

我一直在研究在文件系统上运行的 WordPress 源代码,当我看到这几行时,我真的不太确定它们做了什么?

$stat = stat( dirname( $new_file ));
$perms = $stat['mode'] & 0000666;
@ chmod( $new_file, $perms );

最佳答案

该代码使用位运算来确保文件的权限不高于 666。分解:

// Retrieves the file details, including current file permissions.
$stat = stat( dirname( $new_file ));

// The file permissions are and-ed with the octal value 0000666 to make
// sure that the file mode is no higher than 666. In other words, it locks
// the file down, making sure that current permissions are no higher than 666,
// or owner, group and world read/write.
$perms = $stat['mode'] & 0000666;

// Finally, the new permissions are set back on the file
@chmod( $new_file, $perms );

关于php - stat() 和符号运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2034903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com