Are there any specific considerations when using mkdir() to create directories with specific permissions in PHP?

When using mkdir() in PHP to create directories with specific permissions, it's important to note that the permissions parameter should be specified in octal notation. This means that you need to prefix the numeric value with a 0 (e.g., 0755 for read, write, and execute permissions for owner, and read and execute permissions for group and others). Additionally, make sure to handle potential errors returned by mkdir() to ensure the directory creation was successful.

$dir = 'new_directory';
$permissions = 0755;

if (!mkdir($dir, $permissions, true)) {
    die('Failed to create directory');
} else {
    echo 'Directory created with permissions: ' . decoct(fileperms($dir) & 0777);
}