How does the umask setting in PHP affect the permissions when creating directories with mkdir()?

The umask setting in PHP affects the permissions of newly created directories by modifying the default permissions that are applied when using functions like mkdir(). The umask value is subtracted from the permissions specified when creating directories, resulting in the final permissions set for the directory. To ensure specific permissions are set when creating directories with mkdir(), you can adjust the umask setting before calling the mkdir() function.

// Set the umask to allow specific permissions when creating directories
$old_umask = umask(0);
mkdir('/path/to/directory', 0777, true);
umask($old_umask); // Reset the umask to its original value