How can umask() be used to adjust file permissions before creating a file in PHP?

When creating a file in PHP, the default file permissions are set by the umask value of the system. To adjust file permissions before creating a file, you can use the umask() function in PHP to set a specific umask value. This allows you to control the file permissions that will be applied when creating the file.

// Set the umask value to adjust file permissions
umask(0);

// Create a new file with specific permissions
$file = fopen("newfile.txt", "w");
fclose($file);

// Reset the umask value to default after creating the file
umask(0022);