
April 2nd, 2006, 08:57 AM
|
 |
Moderator From Beyond
|
|
Join Date: Sep 2004
Location: Israel
|
|
|
Displaying images from database
the below code is meant for displaying images that are stored
as BLOB field in the database.
such images can't be directly printed to the screen like you
can print ordinary data.
instead, you must place html image tag on the page, pointing
to the same page and passing correct information then add
proper code to query the database again and send the image
binary contents.
the most generic way (that requires minimal changes)
is having such code:
Code:
'..have this line on top of your code:
Resposne.Buffer = True
'..connection stuff
'..open the database assume recordset is called objRS
'..sample recordset loop is below. note the changes in bold!
Dim recordCounter
recordCounter = 0
Do Until objRS.EOF
If Request("display_image")="1" Then
If recordCounter = CLng(Request("n")) Then
Response.Clear()
Response.ContentType = "image/jpeg"
Response.BinaryWrite( objRS("image_field") )
objRS.Close
Response.END
End If
End If
Response.Write(objRS("field1"))
Response.Write("<img src=""" & Request.ServerVariables("Script_Name") & "?display_image=1&n=" & x & """ />")
'..display fields as usual...
recordCounter = recordCounter+1
objRS.MoveNext
Loop
objRS.Close
|