How can one efficiently determine if an image file exists on a remote server using PHP?

To efficiently determine if an image file exists on a remote server using PHP, you can use the `get_headers()` function to retrieve the headers of the image URL. If the response code is 200, then the image file exists; otherwise, it does not.

function imageExists($url) {
    $headers = get_headers($url);
    return stripos($headers[0], "200 OK") ? true : false;
}

// Example usage
$imageUrl = "https://example.com/image.jpg";
if (imageExists($imageUrl)) {
    echo "Image exists!";
} else {
    echo "Image does not exist.";
}