Both answers from blamonet and Ajie Kurniyawan are somewhat correct but there are more failures than 404(3xx, 4xx, 5xx responses). There are a lot of HTTP responses that would fail to "get/download" a file from a given server.
So I would suggest to check if 200 OK
response.
$file = "http://website.com/dir/filename.php";
$file_headers = @get_headers($file);
if ($file_headers) {
if (strpos($file_headers[0], ' 200 OK') === true) {
echo "File Exists";
} else {
echo "File Doesn't Exist, Access Denied, URL Moved etc";
//you can check more responses here 404, 403, 301, 302 etc
}
} else {
echo "Server has not responded. No headers or file to show.";
}
Error 404: Not found
, for example, so it may have a content, but it may not be what you are expecting. I think its easier to check the headers, don't you think? – lepe Aug 18 '14 at 03:35