User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP section within the Web Development category of DaniWeb, a massive community of 401,956 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,099 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP advertiser: Lunarpages ASP Web Hosting
Views: 5760 | Replies: 4
Reply
Join Date: Oct 2006
Posts: 5
Reputation: chris3000 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
chris3000 chris3000 is offline Offline
Newbie Poster

Display image from a database get me ascii codes

  #1  
Oct 30th, 2006
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"> 

ShowPicture.asp
<%
'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>
 
All i got is tons ascii codes.

Can you help me on this ?

thanx
Chris
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: india
Posts: 143
Reputation: katarey is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 15
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Help Re: Display image from a database get me ascii codes

  #2  
Nov 2nd, 2006
Hi there,

I hope this code will help you!

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
database = Server.MapPath("/files.mdb")

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open database

        SQL = "SELECT * FROM Files WHERE FileID = 3" 
        Set Rs = conn.Execute(SQL)
        Response.BinaryWrite Rs("BinaryData").GetChunk(Rs("BinaryData").ActualSize)
 %>

Best regards,
Rahul Dev
Last edited by katarey : Nov 2nd, 2006 at 10:19 am.
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote  
Join Date: Oct 2006
Posts: 5
Reputation: chris3000 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
chris3000 chris3000 is offline Offline
Newbie Poster

Re: Display image from a database get me ascii codes

  #3  
Nov 2nd, 2006
It give me the same things again. Did you test the code ?

Ascii codes

thanx
Last edited by tgreer : Nov 3rd, 2006 at 3:30 pm. Reason: Removed unnecessary quote block.
Reply With Quote  
Join Date: Jul 2005
Location: india
Posts: 143
Reputation: katarey is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 15
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Solution Re: Display image from a database get me ascii codes

  #4  
Nov 2nd, 2006
Hi Again,

Yes I did test that code and its working

Well have look at these

This file

1.) img.asp
<%@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

    SQL = "SELECT * FROM Files WHERE FileID = 3" 
    Set Rs = conn.Execute(SQL)
    Response.BinaryWrite Rs("BinaryData").GetChunk(Rs("BinaryData").ActualSize)
        
%>



2.) imageDis.asp

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>For Help</title>
</head>
<body>
<img src="img.asp" />
</body>
</html>

3.) img1.asp
<%@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        
%>

Examples:

This file will give output in ASCII codes
1.) http://www.katarey.com/forhelp/img.asp

And this file will show the image,
2.) http://www.katarey.com/forhelp/imageDis.asp

I hope This file that you want!
3.) http://www.katarey.com/forhelp/img1.asp


I hope this will helpful for you, please feel free to ask question if any

Thanks
Regards,
Rahul Dev
Last edited by tgreer : Nov 3rd, 2006 at 3:29 pm. Reason: Removed unnecessary quote block.
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote  
Join Date: Oct 2006
Posts: 5
Reputation: chris3000 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
chris3000 chris3000 is offline Offline
Newbie Poster

Re: Display image from a database get me ascii codes

  #5  
Nov 3rd, 2006
First, Thank you for your help

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.

thanx
Last edited by tgreer : Nov 3rd, 2006 at 3:29 pm. Reason: Removed unnecessary quote block.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP Forum

All times are GMT -4. The time now is 5:53 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC