What are common pitfalls when using getimagesize() in PHP, especially after a server migration?

When using getimagesize() in PHP, a common pitfall after a server migration is that the function may not work properly due to differences in server configurations or file paths. To solve this issue, you can use the $_SERVER['DOCUMENT_ROOT'] variable to get the absolute path to the file.

$image_path = $_SERVER['DOCUMENT_ROOT'] . '/path/to/image.jpg';
$image_info = getimagesize($image_path);

// Check if getimagesize() was successful
if($image_info){
    // Process the image information
    echo "Image width: " . $image_info[0] . "<br>";
    echo "Image height: " . $image_info[1] . "<br>";
    echo "Image type: " . $image_info['mime'] . "<br>";
} else {
    echo "Error getting image size.";
}