Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-13-2003, 11:19 AM   PM User | #1
holty
Regular Coder

 
Join Date: Jun 2002
Location: UK
Posts: 262
Thanks: 0
Thanked 0 Times in 0 Posts
holty is an unknown quantity at this point
Check if Image exists

Hi,

I'm passing through a customers id through a form.

I have images stored of the customer named by their id in an 'images' folder.

So - Customer ID '1' has a image 'images/1.jpg'.

I can display the customers image by doing:

<img src="images/<%= CustomerID %>" width="140" height="100"></td>

where ID is:
CustomerID = request.querystring("ID") & ".jpg"

My question is - if the image doesn't exist in the images folder - can I show some text saying 'Image Required' instead of the little cross?

Any help would be great
holty is offline   Reply With Quote
Old 10-13-2003, 01:25 PM   PM User | #2
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
You can use the FSO fileexists method:
http://www.devguru.com/Technologies/...ileexists.html
raf is offline   Reply With Quote
Old 10-13-2003, 02:01 PM   PM User | #3
holty
Regular Coder

 
Join Date: Jun 2002
Location: UK
Posts: 262
Thanks: 0
Thanked 0 Times in 0 Posts
holty is an unknown quantity at this point
Raf,

I'm trying to use that like this :

FUNCTION FileExist(FileName)
Dim FS, DoesExist
DoesExist = FALSE
SET FS=Server.CreateObject("Scripting.FileSystemObject")
IF (FS.FileExists(FileName)) = TRUE THEN
DoesExist = TRUE
END IF
SET FS=Nothing
FileExist = DoesExist
END FUNCTION


<% IF FileExist(server.mappath("images") & "CustomerID") THEN %>
<img src="images/<%= CustomerID %>" width="140" height="100"></td>
<% else %>
no file exists</td>
<% end if %>


But it doesn't like it - if you look at my previous post the CustomerID is appended to a '.jpg'

can you see what i've doen wrong?
holty is offline   Reply With Quote
Old 10-13-2003, 03:25 PM   PM User | #4
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
Maybe try something like
Code:
dim fileadr
fileadr = "../images/" & request.querystring("ID") & ".jpg"
' comment : or "images/" & request.querystring("ID") & ".jpg" --> depending on where images is situated, relativaly to this file

IF FileExist(server.mappath(fileadr) THEN 
  response.write("<img src="""& fileadr & """ width=""140"" height=""100"">") 
else
  response.write("no file exists")
end if
response.write("</td>")
raf is offline   Reply With Quote
Old 10-13-2003, 03:55 PM   PM User | #5
holty
Regular Coder

 
Join Date: Jun 2002
Location: UK
Posts: 262
Thanks: 0
Thanked 0 Times in 0 Posts
holty is an unknown quantity at this point
Raf - got that working!!

Cheers mate - you've been a great help!
holty is offline   Reply With Quote
Old 10-13-2003, 09:31 PM   PM User | #6
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
You're welcome. Glad you got it working.
raf is offline   Reply With Quote
Old 10-14-2003, 02:22 AM   PM User | #7
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
By the way, glenngv and I came up with a pretty cool client-side solution to this too (whether or not an image (or webpage!) exists, and ways to deal with using client-side javascript)...

I suggested the idea, and he coded it perfectly (exactly what I was thinking!), if you can find it.
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)
whammy is offline   Reply With Quote
Old 10-14-2003, 07:35 AM   PM User | #8
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
http://www.codingforums.com/showthre...threadid=23725

__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 10-15-2003, 04:01 AM   PM User | #9
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
Brilliant.
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)
whammy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:00 AM.


Advertisement
Log in to turn off these ads.