Stat () and Ampersand

I am learning the WordPress source code that works with the file system when I click on these few lines and am really not quite sure what they are doing?

$stat = stat( dirname( $new_file ));
$perms = $stat['mode'] & 0000666;
@ chmod( $new_file, $perms );
+3
source share
3 answers

This code uses bitwise operations to ensure that file permissions do not exceed 666. To break this:

// 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 );
+3
source

It changes the permission to write to the directory. I think so. Check stat () and chmod () .

+1
source

0666 - unix rwxrwxrwx, , $stat['mode'] . 0666, , // , .

0

Source: https://habr.com/ru/post/1727882/


All Articles