How can the issue of incorrect file type validation be resolved when uploading images in PHP?

Issue: Incorrect file type validation can be resolved by checking the file extension against a list of allowed extensions before allowing the file to be uploaded. PHP Code Snippet:

$allowedExtensions = array('jpg', 'jpeg', 'png', 'gif');
$uploadedFile = $_FILES['file']['name'];
$extension = pathinfo($uploadedFile, PATHINFO_EXTENSION);

if (!in_array($extension, $allowedExtensions)) {
    echo "Invalid file type. Please upload a JPG, JPEG, PNG, or GIF file.";
} else {
    // Proceed with uploading the file
}