How can the ownership of files created by PHP scripts be managed in a multi-user environment?

In a multi-user environment, the ownership of files created by PHP scripts can be managed by setting the correct permissions on the files and directories. This can be achieved by using the chown() function in PHP to change the ownership of the files to the desired user or group. Additionally, setting the correct umask value can ensure that newly created files have the desired permissions.

// Set the ownership of a file to a specific user
$filename = 'example.txt';
$user = 'username';
chown($filename, $user);

// Set the umask value to ensure correct permissions on newly created files
umask(0022);