Is there any error in PHP or I am missing something?

Hi!

Is there any error in PHP or I am missing something?
I am trying to see whether the URL Exists or not by using this,


if(file_exists('http://www.abc.com/xyz.html'))
echo "Yes, it Exists";
else
echo "Not exists";

I am always getting Not exists, in the output, whether file exists or not.
Why I am not getting Yes, it Exists, if the file exists in actual.

Hi I got the method.
Thanks.

Please, share your findings. Otherwise this is an entirely wasted page, clogging up the intertubes with no useful information at all. (But congrats on finding a solution yourself.)

Sure,

This is the method,

$ch = curl_init("http://www.abc.com/xyz.html");

curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// $retcode > 400 -> not found, $retcode = 200, found.
curl_close($ch);

if($retcode == 200)
{
echo "Found";
}
elseif($retcode == 400)
{
echo "Error";
}