Okay...
I am looking to detect if a file exists, remote or local with one method.
I have read this:
http://phpbuilder.com/board/showthread.php?t=10297411
And no joy, then the manual with no joy!
I haver tried:
$hdrs = @get_headers($url);
return (bool)is_array($hdrs) ? preg_match('/^HTTP|FTP\\/\\d+\\.\\d+\\s+2\\d\\d\\s+.*$/', $hdrs[0]) : false;
But this only validates the header has HTTP in it. Therefore it also validates a directory listing with these headers:
HTTP/1.1 200 OK =>
Date => Wed, 11 Mar 2009 09:03:03 GMT
Server => Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.7a mod_bwlimited/1.4 PHP/5.2.6
Connection => close
Content-Type => text/html;charset=ISO-8859-1
This is no good - this is a bloody directory not a file!
return (bool)file_exists($url);
This DOES NOT work with remote files, no matter what I try!
return (bool)@fopen($url, "r");
This does work, however, on a local directory say '/test/' - it CREATES the damn directory!
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_TRANSFERTEXT , false);
return (bool)curl_exec($ch);
This just outputs the entire file!
HMMMMM
Please help!
All I want to do is...
"Check if the file exists and if IT IS A FILE" - Is this really do difficult?
C# .net has a built in class to do this - why doesn't php?