How can one ensure that the correct permissions are set when creating a directory in PHP?
When creating a directory in PHP, it is important to ensure that the correct permissions are set to control who can access and modify the directory. This can be done by using the `mkdir` function along with the `chmod` function to set the desired permissions for the directory.
$dir = 'new_directory';
$permissions = 0755; // Example permissions, can be adjusted as needed
if (!file_exists($dir)) {
mkdir($dir);
chmod($dir, $permissions);
echo "Directory created with permissions set to $permissions";
} else {
echo "Directory already exists";
}