What potential issues can arise when using getimagesize in PHP for image file uploads?

One potential issue when using getimagesize in PHP for image file uploads is that malicious users can manipulate the image data to bypass file type checks. To solve this, you can use the exif_imagetype function instead, which checks the image file's MIME type directly.

// Check image MIME type using exif_imagetype
$image_type = exif_imagetype($_FILES['file']['tmp_name']);

if($image_type === IMAGETYPE_JPEG || $image_type === IMAGETYPE_PNG) {
    // Process the image upload
} else {
    // Invalid image type
    echo "Invalid image type. Only JPEG and PNG files are allowed.";
}