我一直在研究在文件系统上运行的WordPress源代码,当我点击这几行并且我真的不太清楚他们做了什么?
$stat = stat( dirname( $new_file ));
$perms = $stat['mode'] & 0000666;
@ chmod( $new_file, $perms );
答案 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)
答案 2 :(得分:0)
0666
是unix rwxrwxrwx
权限的八进制表示法,因此我假设$stat['mode']
返回该文件夹的权限。然后,他们与0666
掩码进行按位AND运算,以检查您是否至少 读取/写入/执行自己,组和其他人的权限。