如何检查URL图像是否存在于PHP中 [英] How to check Url Image is exist or not in php
本文介绍了如何检查URL图像是否存在于PHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力从数据库和数据库中获取图像URL;在php中显示图像,如下所示
I am working around fetch image URL from database & show image in php like following
<?php
$row['blog_url'] = "http://www.nasa.gov/images/content/711375main_grail20121205_4x3_946-710.jpg";
<img src="<?php echo $row['blog_url']; ?>" height="200" width="200" alt="image"/>
?>
但是如果图像没有从指定的URL作为blog_url加载,我想显示no_imgae.jpeg
but i want display no_imgae.jpeg if image not getting loaded from specified url as blog_url
在php中是否存在任何找出图像的方法
if there any way to find out image is exist or not in php
提前谢谢...
推荐答案
此功能将解决您的问题:
This function will solve your problem :
function checkRemoteFile($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
// don't download content
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==FALSE)
{
return true;
}
else
{
return false;
}
}
只需在此function
中传递image url
,如果图像存在则返回yes
,否则返回false
Just pass the image url
in this function
and it will return yes
if image exists otherwise false
这篇关于如何检查URL图像是否存在于PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文