note 88872 deleted from function.file-exists by danbrown

From: Date: Wed, 11 Feb 2009 19:35:54 +0000
Subject: note 88872 deleted from function.file-exists by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-150508@lists.php.net to get a copy of this message
Note Submitter: nnikolay at gmail dot com Reason: integrated ---- Hi in the function below there is bug, because there can be more digits 200 in the header, like 2009 for example. Here is the fix: <?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); } } ?>

« previous php.notes (#150508) next »