File on remote server

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
pharmacomancer
Forum Newbie
Posts: 1
Joined: Sat Apr 03, 2004 4:13 pm

File on remote server

Post by pharmacomancer »

Hello all,

I was wondering if it is possible to check if a file exists on a remote server using php. For example I would like to create a simple funcion that for a given input "www.anyserver.com/anyfile.htm" returs true if the file exists or false otherwise. If it is possible can anybody tell me how to do it?


Thanks,

-Pharmacomancer
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

Post by reverend_ink »

Code: Select all

<?php
if (file_exists("http://www.anydomain.com/anyfile.htm")){
		
		echo ("whatever"); 
}
else {
                                echo ("whatever else");
}

?>
That should do it for you
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Not sure you can use file_exists on remote urls. So you could also do:

Code: Select all

$foo = file('http://foo.com/bar.php');
if(!empty($foo)){
  //it exists
} else {
  //it doesn't
}
Post Reply