...

View Full Version : Function to see if image exists?



holty
11-26-2003, 09:13 AM
Hi,

Is there a function that I can use to see whether an image exists?

i.e. - I would like to see if 21656.jpg is exists - if it doesn't the text for that item would not be a link to the image.

Thanks

Nightfire
11-26-2003, 10:34 AM
Use the file_exists() (http://www.php.net/file_exists) function :)



<?php
$img = "21656.jpg";

if(file_exists($img)){
echo '<img src="' . $img . '">';
}
?>

holty
11-27-2003, 09:57 AM
Hi,

I've already tried that - but it didn't like because the file reside on a different website.

I have also tried -



if (@fclose(@fopen("http://www.website.com/images/21656.jpg", "r"))) {
print("File exists.");
} else {
print("File does not exist.");
}

?>


but it returns 'File does not exist' when it does if I cut and paste it into a browser window

Any ideas?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum