All i wanna do is simple, I wanna display an image from an access database.
I try alot of things to no result. Like ascii code or nothing but a blank image with a red 'X'.
Here is the code :
<%
set conn=server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.jet.oledb.4.0"
conn.Open(server.MapPath("test1.mdb"))
set rs= conn.Execute("SELECT photo FROM photos where ID=1")
Response.ContentType="image/jpg"
Response.BinaryWrite(rs("photo"))
conn.Close
%>
I also tried a file named ShowPicture.asp and call it from another file like this:
<IMG SRC="ShowPicture.asp?PhotoId=1">
<em>ShowPicture.asp</em>
<%
'Declare Variables
Dim sql
Dim rs
Dim conn
Dim userID,str
userID = Request("PhotoId")
If userID = "" Then userID = 0
'Instantiate Objects
Set conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
'Open connection
conn.Provider="Microsoft.jet.oledb.4.0"
conn.Open(server.MapPath("test1.mdb"))
'Get the specific image based on the ID passed in a querystring
str = "SELECT photo FROM photos where ID =" & userID
rs.Open str, conn,3,3
if rs.eof then 'No records found
Response.End
else 'Display the contents
Response.ContentType = "image/jpg"
Response.BinaryWrite(rs("photo"))
end if
'destroy the variables.
rs.Close
conn.Close
set rs = Nothing
set conn = Nothing
%>
I also try this :
<body>
<%
set conn=server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.jet.oledb.4.0"
conn.Open(server.MapPath("test1.mdb"))
set rs= conn.Execute("SELECT photo FROM photos where ID=1")
Response.ContentType="image/jpg"
%>
<img src="<%Response.BinaryWrite(rs("photo"))%>">
<% conn.Close %>
</body>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
database = Server.MapPath("DATABASE.mdb")
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open database
Dim SQL
Dim FileID
FileID = 4
SQL = "SELECT * FROM Files WHERE FileID = " & FileID
Set Rs = conn.Execute(SQL)
If Not Rs.EOF Then
Response.AddHeader "content-disposition", "inline; filename=" & oRs("FileName")
Response.AddHeader "content-length", Rs("BinaryData").ActualSize
Response.ContentType = Rs("ContentType")
Response.BinaryWrite Rs("BinaryData")
Else
Response.Write("File could not be found")
End If
%>
But the problem persist, I again get some ascii codes but I don't think its the asp code.
When i put some picture in access database , access give them the type : package. I think it is the source of the problem because I have another database that I download from the internet where picture's type are long binary data and I can display them correctly with your code.
Can you show me how to put long binary type in access database ?
I try to convert but there is no other choice in the convert list.