note 88872 added to function.file-exists

From: Date: Wed, 11 Feb 2009 19:34:00 +0000
Subject: note 88872 added to function.file-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-150507@lists.php.net to get a copy of this message
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); } } ?> ---- Server IP: 217.160.72.57 Probable Submitter: 62.143.115.3 ---- Manual Page -- http://www.php.net/manual/en/function.file-exists.php Edit -- https://master.php.net/note/edit/88872 Del: integrated -- https://master.php.net/note/delete/88872/integrated Del: useless -- https://master.php.net/note/delete/88872/useless Del: bad code -- https://master.php.net/note/delete/88872/bad+code Del: spam -- https://master.php.net/note/delete/88872/spam Del: non-english -- https://master.php.net/note/delete/88872/non-english Del: in docs -- https://master.php.net/note/delete/88872/in+docs Del: other reasons-- https://master.php.net/note/delete/88872 Reject -- https://master.php.net/note/reject/88872 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150507) next »