What potential pitfalls should be avoided when using the getimagesize function in PHP for image uploads?

One potential pitfall to avoid when using the getimagesize function in PHP for image uploads is not checking for errors or malicious input. To prevent security vulnerabilities, always validate the uploaded file type before using getimagesize to retrieve image dimensions.

// Check if the uploaded file is an image before using getimagesize
if (isset($_FILES['image']['tmp_name']) && getimagesize($_FILES['image']['tmp_name'])) {
    // Proceed with getting image dimensions
    $imageSize = getimagesize($_FILES['image']['tmp_name']);
    $width = $imageSize[0];
    $height = $imageSize[1];
} else {
    // Handle error or reject the file
    echo "Invalid image file uploaded.";
}