I am in the middle of coding up a property portal. I am stuck on checking images. I know how to check if an image url is set. But the problem is detecting if there is actual
Use getimagesize() to ensure that the URL points to a valid image.
if (getimagesize($imageURL) !== false) {
// display image
}
function is_webUrl($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;
}
}
if(is_webUrl('http://www.themes.tatwerat.com/wp/ah-personal/wp-content/uploads/2016/08/features-ah-wp-view.jpg')) {
echo 'yes i found it';
}else{
echo 'file not found';
}
function exists($uri)
{
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $code == 200;
}