stat()和&符号运算符

时间:2010-01-09 20:49:26

标签: php

我一直在研究在文件系统上运行的WordPress源代码,当我点击这几行并且我真的不太清楚他们做了什么?

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

3 个答案:

答案 0 :(得分:3)

该代码使用按位运算来确保文件的权限不高于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 );

答案 1 :(得分:1)

它改变了允许在目录中写入的权限..我想。查看stat()chmod()

答案 2 :(得分:0)

0666是unix rwxrwxrwx权限的八进制表示法,因此我假设$stat['mode']返回该文件夹的权限。然后,他们与0666掩码进行按位AND运算,以检查您是否至少 读取/写入/执行自己,组和其他人的权限。