What are some potential reasons for the mkdir() function in PHP not setting the correct permissions for a newly created directory?

The mkdir() function in PHP may not set the correct permissions for a newly created directory due to the umask setting, which can affect the default permissions assigned to newly created files and directories. To ensure the correct permissions are set, you can explicitly specify the desired permissions using chmod() after creating the directory.

$dir = 'new_directory';
$permissions = 0777; // Set desired permissions here

if (!is_dir($dir)) {
    mkdir($dir);
    chmod($dir, $permissions);
}