wp config - Syntax of FS_CHMOD_DIR and FS_CHMOD_FILE

I ran into an issue today with files uploaded through the Wordpress Backend not getting the correct permissions. The per

I ran into an issue today with files uploaded through the Wordpress Backend not getting the correct permissions. The permission on the new 2018 folder in the uploads directory as well as the files within it were too tight, the webserver user couldn't even access them. I found the constants FS_CHMOD_DIR and FS_CHMOD_FILE that can be used to overwrite the default permissions for uploaded files. The Wordpress Codex suggests using the the following settings in the wp-config.php:

define( 'FS_CHMOD_DIR', ( 0755 & ~ umask() ) );
define( 'FS_CHMOD_FILE', ( 0644 & ~ umask() ) );

However, I haven't been able to find documentation on the syntax of those constants. The octal notation of the permissions is clear, but what is up with the ampersand, the swung dash and the umask command without a parameter? This article by wpbeginner mentions those constants as well, however it only mentions defining the constants with the octal values alone. What's the difference between that and the longer command above?

I ran into an issue today with files uploaded through the Wordpress Backend not getting the correct permissions. The permission on the new 2018 folder in the uploads directory as well as the files within it were too tight, the webserver user couldn't even access them. I found the constants FS_CHMOD_DIR and FS_CHMOD_FILE that can be used to overwrite the default permissions for uploaded files. The Wordpress Codex suggests using the the following settings in the wp-config.php:

define( 'FS_CHMOD_DIR', ( 0755 & ~ umask() ) );
define( 'FS_CHMOD_FILE', ( 0644 & ~ umask() ) );

However, I haven't been able to find documentation on the syntax of those constants. The octal notation of the permissions is clear, but what is up with the ampersand, the swung dash and the umask command without a parameter? This article by wpbeginner mentions those constants as well, however it only mentions defining the constants with the octal values alone. What's the difference between that and the longer command above?

Share Improve this question asked Jan 5, 2018 at 10:18 MoritzLostMoritzLost 1771 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 4

The basic syntax for define() is:

define ( $name, $value )

In the above definition, the value is:

( 0755 & ~ umask() )

The '&' (ampersand) is the 'And' bitwise operator, the '~' (tilde) is the 'Not' bitwise operator, and the umask() function returns the current umask.

To answer your question in short (if your are interested in learning bitwise operations, there are plenty of resources on that), the above "syntax" is in fact an operation, that substracts the current umask from the definition you provide.

So, for example, if you provide 0644 and the current umask is 0640, then the effective permissions set will be 640. Why or when would you do that? Well, you would in the cases where you want to specify certain permissions, but not being more permissive than the default umask.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745148217a4613744.html

相关推荐

  • wp config - Syntax of FS_CHMOD_DIR and FS_CHMOD_FILE

    I ran into an issue today with files uploaded through the Wordpress Backend not getting the correct permissions. The per

    1小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信