Hi,
I am building a website where users can place advertisements with images. I have decided to place the images in an Access database to ensure the right images are matched the correct advertisements. My problem is that I can retrieve all of the data from the table which holds the photos (eg, filename, file size, content type) except for the actual photo itself. When I try to download the photo or press the hyperlink to display the photo all I get is the square with the red cross. I do not get any error messages.
Does anyone know why this is happening. My code is below:
Advertisement page
show_picture.asp – page that retrieves the imageCode:<% Response.Buffer = True ' Connection String Dim connStr connStr = ""Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\wwwsites\website.com\odbc\database.mdb;"%> ' Recordset Object Dim rs Set rs = Server.CreateObject("ADODB.Recordset") ' opening connection rs.Open "select [account_id],[file_name],[file_size],[content_ type],[photo] from photo order by [account_id] desc", connStr, 3, 4 If Not rs.EOF Then Response.Write "<tr><td colspan=""7"" align=""center""><i>" Response.Write "No. of records : " & rs.RecordCount Response.Write ", Table : photo</i><br>" Response.Write "</td></tr>" While Not rs.EOF Response.Write "<tr><td>" Response.Write rs("account_id") & "</td><td>" Response.Write "<a href=""show_picture.asp?account_id=" & rs("account_id") & """>" Response.Write "<img src=""show_picture.asp?account_id=" & rs("account_id") & """>" Response.Write rs("file_name") & "</a></td><td>" Response.Write rs("file_size") & "</td><td>" Response.Write rs("content_type") & "</td><td>" Response.Write "</td></tr>" rs.MoveNext Wend Else Response.Write "No Record Found" End If rs.Close Set rs = Nothing %> </table> </body> </html>
Thanks in advanceCode:<%@LANGUAGE="VBSCRIPT"%> <% ' Retrieves binary files from the database Response.Buffer = True 'Declare Variables.. Dim Image Dim rs Dim connStr Dim ID,str Dim PicSize ' ID of the file to retrieve ID = Request.QueryString("account_id") If ID = "" Then ID = 0 If Len(ID) < 1 Then response.write("Image not here") End If If ID <> "" then 'Instantiate Objects Set connStr = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.Recordset") ' Connection String connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\wwwsites\website.com\odbc\database.mdb;" 'Get the specific image based on the ID passed in a querystring str = "SELECT photo, content_type FROM photo where account_id =" & ID rs.Open str, connStr, adOpenDynamic if not (rs.eof and rs.bof) then PicSize = rs("Photo").ActualSize response.write PicSize Image = rs("photo").GetChunk(PicSize) Response.ContentType = "image/pjpeg" Response.BinaryWrite Image else Response.Write "ID '" & ID & "' not found in DB." end if End If 'destroy the variables. rs.Close set rs = Nothing set connStr = Nothing %>





Bookmarks