How can PHP be used to validate file types server-side before allowing the upload to proceed?

When allowing file uploads on a website, it is important to validate the file type server-side to prevent malicious files from being uploaded. PHP can be used to check the file type before allowing the upload to proceed. This can be done by checking the MIME type of the file using the `$_FILES` superglobal array.

// Check if the file type is allowed
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif'];
if (!in_array($_FILES['file']['type'], $allowedTypes)) {
    echo 'Invalid file type. Only JPEG, PNG, and GIF files are allowed.';
    exit;
}

// If the file type is allowed, proceed with the upload
move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $_FILES['file']['name']);
echo 'File uploaded successfully.';