How can getimagesize() be used to verify the presence of an image at a URL?

To verify the presence of an image at a URL, you can use the getimagesize() function in PHP. This function returns an array with the dimensions and MIME type of the image if the URL points to a valid image file. By checking if getimagesize() returns false or an array with valid image information, you can determine if an image exists at the given URL.

$url = 'https://example.com/image.jpg';

$image_info = @getimagesize($url);

if($image_info !== false) {
    echo 'Image exists at URL: ' . $url;
} else {
    echo 'No image found at URL: ' . $url;
}