I'm trying to figure out whether a file exists given a URL. The domain will always be valid, it's just that I need to figure out when a generate URL to a file at the domain is invalid. I'm doing it like this currently:
$fp = @fopen($url, "r");
$contents = fread ($fp, 1000000);
if (!(ereg("404",$contents))) {
fclose($fp);
return "error404";
}
else {
fclose($fp);
return "non error404";
}
}
This is giving me inconsistent results. I tried just doing an fopen and checking whether the $fp was true or false, but problem is that the domain is always valid and I actually get data back (error 404) and $fp is NEVER false.
My above implementation is working inconsistently and it says the URL is valid when in fact it is not.
Can anyone help?