What are best practices for setting file permissions in PHP scripts for file uploads?

When handling file uploads in PHP scripts, it is important to set appropriate file permissions to ensure security and prevent unauthorized access. A common best practice is to set the permissions of uploaded files to be readable and writable only by the owner, while restricting access for others.

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

// Move uploaded file to designated directory
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadedFile)) {
    // Set file permissions to be readable and writable only by the owner
    chmod($uploadedFile, 0600);
    echo "File uploaded successfully.";
} else {
    echo "Error uploading file.";
}