Page 1 of 1

file_exists(on someone elses website)

Posted: Wed May 30, 2007 10:55 am
by superdezign
I run file_exists('posting.php');
It returns false.

Is it because I am testing locally, or because you can't check remote files through file_exists()?

Posted: Wed May 30, 2007 11:04 am
by feyd
The manual pretty much explains it. file_exists() uses stat() which, until PHP 5, did not support remote requests.

Posted: Wed May 30, 2007 11:04 am
by volka
http://de2.php.net/file_exists wrote:As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to Appendix N, List of Supported Protocols/Wrappers for a listing of which wrappers support stat() family of functionality.
And the http wrapper page says

Posted: Wed May 30, 2007 11:21 am
by superdezign
Haha, I need to read more carefully.

Is there a way to check if a remote file exists?

I'd like to ensure that it's type matches the regex /^image\//.

Posted: Wed May 30, 2007 11:24 am
by feyd
Use cURL to request the headers (or get_headers()). Analyze the contents.

A return code in the 200's means the file is apparently there.

Posted: Wed May 30, 2007 11:34 am
by superdezign
Oh my god, like, get_headers() is sooo, like, PHP5, or whatever.

I haven't even touched cURL before.... I guess it's that time to learn stuff again.