What are some alternative methods, aside from checking file extensions, to ensure secure image uploads in PHP?

One alternative method to ensure secure image uploads in PHP is to use the `getimagesize()` function to check the image file's MIME type. This function returns an array containing information about the image, including its MIME type. By checking the MIME type against a list of allowed types, you can verify that the uploaded file is actually an image.

// Check if the uploaded file is an image by using getimagesize()
$image_info = getimagesize($_FILES["file"]["tmp_name"]);
if($image_info !== false) {
    $allowed_mime_types = array("image/jpeg", "image/png", "image/gif");
    if(in_array($image_info["mime"], $allowed_mime_types)) {
        // Process the file as an image
    } else {
        // File is not an allowed image type
    }
} else {
    // File is not an image
}