Check for images in a separate domain

So, I work on a website where the images for the catalog are listed in a separate domain than the database / website with the catalog. The way it was set up is the surname of the surname, and the first initials of the spouses make up the name of the image, so ...

John and Kathy Doe

corresponds to the image:

doe-jk.jpg

What I want to do is the logic that displays each list from the database, and checks if this image exists in another domain, something like this:

$picture_name = "http://totally-different-domain.com/".$file_name;
    if ( isset( $picture_name ) )
    {
       echo $picture_name;
    }
    else
    {
       echo 'empty.jpg';
    }

Does anyone know how I can do this when files exist in separate domains?

EDIT: , , script http://domain1.com/directory.php, , directory.php http://totally-different-domain.com/doe-jk.jpg

+3
2

, get_headers , 404. .

$url = 'http://totally-different-domain.com/doe-jk.jpg'
$response = get_headers($url, 1);
$file_exists = (strpos($response[0], "404") === false);
+10

is_readable() , .

$picture_name = "http://totally-different-domain.com/".$file_name;
if (!is_readable($picture_name)) {
    $picture_name = 'empty.jpg';
}
echo $picture_name;
+2

Source: https://habr.com/ru/post/1772781/


All Articles