Books & Music
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
News & Politics
Religion & Spirituality
Travel & Culture
TV & Movies
Handling Missing Graphic Files
It's common to use ASP to display graphic images on the fly. You can have your code check to make sure the graphic file is actually there - and show a default image if it is missing for some reason.
The command you're going to use here is FileExists - the command checks to see if the file you specify actually exists on the server. You can then do different processing based on whether or not you find the specified file.
Let's say you have an inventory system where all of your products are given sequential numbers - from P1 to P1000 and so on. Your image files are named to match, so P1.jpg, P2.jpg, etc. This normally makes it very easy for you to automatically show the image that goes with a given product.
If you have to remove an image for some reason, the following code will show a default image until you get around to putting a new proper image into the directory.
set picFSO = createobject("Scripting.FileSystemObject")
PicPath = "/images/products/P" & ProductID & ".jpg"
PicFullPath = Server.MapPath(PicPath)
if picFSO.FileExists(PicFullPath) THEN
FoundImage = TRUE
FoundImage = FALSE
Once you've got that FoundImage set properly, you can now do whatever if-then statements you like. You can use a standard IMG SRC= to display that proper PicPath entry if FoundImage is true, or show another default entry if the FoundImage is false.
| Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map
Content copyright © 2015 by Lisa Shea. All rights reserved.
This content was written by Lisa Shea. If you wish to use this content in any manner, you need written permission. Contact Lisa Shea for details.
Website copyright © 2015 Minerva WebWorks LLC. All rights reserved.