File_exists on a a 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
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

File_exists on a a remote server

Post by mzfp2 »

Hi

I'm having trouble determining if a file eixts oir not a remote server using the following method

if (file_exists('http://remoteserver/image.jpg') == true)
{
}

I can display the image file, and even access its attributes such as height, width and file type, just cannot get the file_exist statement to correctly determine if the file actually exists or not (always returns false).

Any help would be greatly appreciated.

Thanks
Getran
Forum Commoner
Posts: 59
Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:

Post by Getran »

maybe just try it like this ?

Code: Select all

<?php
$check = file_exists('http://remoteserver/image.jpg');
if (isset($check))
{
// w/e
}

?>
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Geltran, isset checks whether it was set, file_exists() returns TRUE or FALSE. So your if statement would happen no matter what.

mzfp2:

Code: Select all

<?php
if (file_exists("http://remoteserver/image.jpg")){
  echo "File exists!";
}
else {
  echo "No file..";
}
?>
Getran
Forum Commoner
Posts: 59
Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:

Post by Getran »

i see, well i'm still a nub to PHP anyway :P
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

http://www.php.net/manual/en/ will help with that. 8)
Getran
Forum Commoner
Posts: 59
Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:

Post by Getran »

lol
Post Reply