Jump to content

If file not exists


sotusotusotu

Recommended Posts

Hi all,

 

For some reason I am having trouble displaying a default image when an image doesn't exist.  I have written the following code.  Or is there another way of doing this?

 

Thanks

 

 

<?php if (file_exists ($serverPath."images/".$speakerRecord['image'])) {?>

<img src="<?php print $relativePath."images/".$speakerRecord['image'];?>" alt="<?php print $speakerRecord['speaker_name'];?>" class="featured_events_image_l"/>

<?php } else { ?>

<img src="speaker_large.gif" alt="" />

<?php } ?>

Link to comment
https://forums.phpfreaks.com/topic/84271-if-file-not-exists/
Share on other sites

The source code for the image is:

 

<img src="images/speakers/" alt="Estelle Hersenzhorn, WRAP" />

 

The code works fine when the image exists and returns the correct image.  The problem just seems to be that it thinks that an image always seems to exist.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/84271-if-file-not-exists/#findComment-429185
Share on other sites

this

 

if (file_exists ($serverPath."images/".$speakerRecord['image']))

 

should be

 

if (file_exists ($serverPath."images/".$speakerRecord['image']) && !is_dir($serverPath."images/".$speakerRecord['image']))

 

what is happening $speakerRecord['image'] is not coming in and therefore it checking the dir and returning true

 

Link to comment
https://forums.phpfreaks.com/topic/84271-if-file-not-exists/#findComment-429197
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.