file_exists(on someone elses website)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

file_exists(on someone elses website)

Post 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()?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The manual pretty much explains it. file_exists() uses stat() which, until PHP 5, did not support remote requests.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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\//.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
Post Reply