Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display an image stored in Access/SQL Server on web page?

Status
Not open for further replies.

zakman

Programmer
Aug 15, 2001
49
0
0
US
Suppose you have an image stored in either Access or SQL
Server...

Has anyone had any experience with uploading & storing an
image into either one of these databases?

On the flip side, has anyone been able to retrieve the
image from the database and display it on a web page?

From what I gather, it would be far easier to keep the
approach that I have now... which is storing the pathname
in the database & keeping the actual image file on the
disk. But I would like to see how it is done from database
storage side...

Thanks everyone!

--Kevin
 
In this example I am showing multiple images on the page. It is including showimage.asp as the src of the image. Obviously you could take this code and modify it to make showimage.asp universal. Also do not save images to the DB unless you absolutely have to. Saving paths is a much better option!!!

-------------------Page1--------------------------

<IMG SRC=&quot;showimage.asp?ID=<%=rs(&quot;ID&quot;)%>&quot;>



-------------Showimage.asp-----------------------
<%
set cn=createobject(&quot;adodb.connection&quot;)
set rs=createobject(&quot;adodb.recordset&quot;)

cn.open session(&quot;connectionstring&quot;)

mysql=&quot;select sigJPG from service_signature where ID=&quot; & requesT(&quot;ID&quot;)
rs.open mysql,cn,3,3

response.contenttype=&quot;image/jpg&quot;
response.binarywrite rs(&quot;sigjpg&quot;)
rs.Close
cn.Close
set rs=nothing
set cn=nothing
%>
 
Thank you for the prompt reply Kifaro...

I'll have to try that later today...

Any slick ways for inserting the image into the record?

--Kevin

 
Just so that you all know....

I believe its inefficient to store image files in a
database. I agree with Kifaro in that one should store
the image on disk and store the filename in the database.

But, for arguments' sake, I am looking at how one would
attempt to store/retrieve images in database...

--Kevin
 
Along the same line....

Suppose that you have an archive of pictures on another
server, and you DO NOT want the client's browser to see
exactly where the image was retrieved from... also, you
are not allowed to map a drive on the web server...

The <IMG SRC=&quot;~~~&quot;> tends to reveal the true location of
the image file on the server.

I have looked at a few different scenerios and one also
must consider the multi-user aspect as well.

Any ideas?

--Kevin
 
Here is a sample of how to write to the DB. Now I am sure you are asking why did I write an image to the database when I said don't do it. The reason for myself is crystal reports, it doesn't take a dynamic path to display images so I needed to put the .jpg in the db, otherwise they would be in a dir.

If you are allowed to access the drive at run time, I would copy the image to a directory on your web server based on the user call. You can name the image the time or something that way you can write a vb program to clean up the images there by keeping the disk drive nice and tidy.

Aaron


<%
set cn=createobject(&quot;adodb.connection&quot;)
set rs=createobject(&quot;Adodb.recordset&quot;)
Set mstream = createobject(&quot;ADODB.Stream&quot;)
cn.Open &quot;localserver&quot;,&quot;sa&quot;,&quot;securityonejpbn&quot;

set objSig=createobject(&quot;pjtSigToJPG.clsSigToJPG&quot;)
bRet=objSig.Create (&quot;C:\testjpg.jpg&quot;,request(&quot;signature&quot;))

iUserID=session(&quot;iUserID&quot;)

mysql=&quot;select * from service_signature&quot;
rs.open mysql,cn,3,3

rs.addnew

mstream.Type = 1
mstream.Open
mstream.LoadFromFile &quot;c:\testjpg.jpg&quot;
rs(&quot;SigJpg&quot;).Value = mstream.Read


rs(&quot;ServiceID&quot;)=requesT(&quot;TicketID&quot;)
rs(&quot;RealName&quot;)=request(&quot;RealName&quot;)
rs(&quot;UserID&quot;)=iUserID
rs.update
rs.close

response.redirect &quot;sig.asp?crypt=&quot; & request(&quot;crypt&quot;) & &quot;&ticketID=&quot; & request(&quot;ticketID&quot;)

%>


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top