So I'm working on a website where the images for a directory are listed on a separate domain than the database/website that has the directory. The way it has been set up, is the families last name plus the spouses first initials make up the image name, so that...
John and Kathy Doe
would correspond to the image:
doe-jk.jpg
What I want to do, is in the logic that displays each listing from the database, it checks to see if this image exists on the other 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 anybody know how I can do this when the files exist on separate domains?
EDIT: What I mean by se开发者_Go百科parate domains, is that the script exists at http://domain1.com/directory.php, and the image that is included in directory.php is at http://totally-different-domain.com/doe-jk.jpg
You can check if a file exists on another domain by using the get_headers function and checking if you get a 404. Ex.
$url = 'http://totally-different-domain.com/doe-jk.jpg'
$response = get_headers($url, 1);
$file_exists = (strpos($response[0], "404") === false);
is_readable()
checks both for existence and readability.
$picture_name = "http://totally-different-domain.com/".$file_name;
if (!is_readable($picture_name)) {
$picture_name = 'empty.jpg';
}
echo $picture_name;
精彩评论