Page 1 of 1

File on remote server

Posted: Sat Apr 03, 2004 4:13 pm
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

Posted: Sat Apr 03, 2004 8:13 pm
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

Posted: Sat Apr 03, 2004 8:36 pm
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
}