What are common reasons for a folder with 0777 permissions to default to 0755 in PHP?

When a folder with 0777 permissions defaults to 0755 in PHP, it is likely due to the umask setting on the server. The umask value restricts the default permissions applied when creating new files or directories. To ensure that the folder maintains the desired 0777 permissions, you can explicitly set the permissions using the chmod() function in PHP.

$folderPath = '/path/to/folder';
$desiredPermissions = 0777;

// Set the folder permissions explicitly
if (!file_exists($folderPath)) {
    mkdir($folderPath, $desiredPermissions, true);
} else {
    chmod($folderPath, $desiredPermissions);
}