erdubya
01-17-2008, 07:04 PM
I have a set of images in my /img folder... for example:
rick_james.jpg
michael_jackson.jpg
barbara_streisand.jpg
prince.jpg
stevie_ray_vaughn.jpg
I have a script that uses a variable $name that displays the images listed above.
<img src="/img/<?php echo $name; ?>.gif">
When $name = rick_james, michael_jackson, etc... all is good and it shows the appropriate picture.
BUT say if the variable $name = kenny_loggins, then it throws a 404, saying img/kenny_loggins.gif does not exist.
What is happening is that my server is working overtime trying to display images that do not exist.
How can I write code that fails properly?
in other words, if the image does not exist, don't try to look for it, if it does then go ahead and display it.
Thanks!
rick_james.jpg
michael_jackson.jpg
barbara_streisand.jpg
prince.jpg
stevie_ray_vaughn.jpg
I have a script that uses a variable $name that displays the images listed above.
<img src="/img/<?php echo $name; ?>.gif">
When $name = rick_james, michael_jackson, etc... all is good and it shows the appropriate picture.
BUT say if the variable $name = kenny_loggins, then it throws a 404, saying img/kenny_loggins.gif does not exist.
What is happening is that my server is working overtime trying to display images that do not exist.
How can I write code that fails properly?
in other words, if the image does not exist, don't try to look for it, if it does then go ahead and display it.
Thanks!