What best practices should be followed when setting file permissions for uploaded files in PHP?

When setting file permissions for uploaded files in PHP, it is important to follow best practices to ensure security and prevent unauthorized access. One common approach is to set the file permissions to restrict access to the owner and group, while allowing read and write access only when necessary. This can help prevent malicious users from executing or modifying uploaded files.

// Set file permissions for uploaded files
$uploadDir = 'uploads/';
$uploadedFile = $uploadDir . basename($_FILES['file']['name']);

// Set file permissions to restrict access
chmod($uploadedFile, 0644);