note 88859 deleted from function.file-exists by danbrown
| From: | danbrown@php.net | Date: | Thu, 12 Feb 2009 03:19:20 +0000 |
| Subject: | note 88859 deleted from function.file-exists by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150544@lists.php.net to get a copy of this message | ||
Note Submitter: nnikolay at gmail dot com
----
Hi! There were a solution with @get_headers in one post below, but I thing here is a better one
function, because in this example is a timeout solution included!
<?php
function checkImage($image_url, $timeout = 3) {
$ch = curl_init($image_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, true);
$res = curl_exec($ch);
curl_close($ch);
preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/", $res, $matches);
$code = (int) end($matches[1]);
if ($res !== false && $code == 200) {
return ((bool) true);
} else {
return ((bool) false);
}
}
?>