检查图片是否存在于单独的域中
因此,我正在开发一个网站,其中目录的图像列在与具有该目录的数据库/网站不同的域中。它的设置方式是家庭姓氏加上配偶的名字首字母组成图像名称,这样......
John and Kathy Doe
就会对应于图像:
doe-jk.jpg
我想要做的是在显示每个列表的逻辑中数据库,它检查该图像是否存在于其他域中,如下所示:
$picture_name = "http://totally-different-domain.com/".$file_name;
if ( isset( $picture_name ) )
{
echo $picture_name;
}
else
{
echo 'empty.jpg';
}
当文件存在于不同的域中时,有人知道如何执行此操作吗?
编辑:我所说的单独的意思域,是脚本存在于 http://domain1.com/directory.php 处,并且图像包含在directory.php中的内容位于 http://totally- Different-domain.com/ doe-jk.jpg
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 separate 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 get_headers 函数检查另一个域中是否存在文件,并检查是否收到 404。
You can check if a file exists on another domain by using the get_headers function and checking if you get a 404. Ex.
is_read()
检查是否存在以及可读性。is_readable()
checks both for existence and readability.