View Single Post
Old 02-03-2013, 03:37 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,064 Times in 4,033 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Yes, it's not hard.

Assuming that you are using <img src="getImage.asp?id=73" /> you would need to do
Code:
<%
' make sure that the < in the above line is the FIRST CHARACTER in the ASP page!!!
'
' what image was requested?
imageid = CLNG( Request("id") )

... here you need to go find the image to match the imageid ...
... we will assume that you find some FILENAME, here called fname:
fname = ... you supply this code ...

' Set the content type to the specific type that you are sending.
' Find the extension of the fname, thus:
period = InStrRev(fname,".")
If period = 0 Then Response.End
fext = Mid(fname,period+1)

' Then tell the browse what the type is:
Response.ContentType = "image/" & fext

Set strm = Server.CreateObject("ADODB.Stream")
strm.Open
strm.Type = 1 ' binary stream

' assuming fname is *RELATIVE* to the current directory:
strm.LoadFromFile Server.MapPath(fname)
' (omit the Server.MapPath if fname is already a full Windows path!)

Response.BinaryWrite strm.Read ' write the entire image out to the browser

strm.Close
Set strm = Nothing
Response.End ' important!
%>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
esthera (02-03-2013)