How to deal with images in ASP

Source: Internet
Author: User
Tags dsn header query table name
In the use of ASP programming, many times to use the image. For the simple processing of a image from the database, the method has been said a lot, it is not difficult to see the following code: Here, let's say you have a database named: Pubs, in the database has a name: pub_info table, in the table has a logo blob column. We found a picture of pub_id=0736 's people.
File&: showimg.asp
***************************************
<%@ language= "VB"%>
<%
Clear out the existing HTTP header information
Response.Expires = 0
Response.Buffer = True
Response.Clear

Change the HTTP header to reflect this is being passed.
Response.ContentType = "Image/gif"

Set cn = Server.CreateObject ("Adodb.connection")
The following open line assumes your have set up a system datasource
By the name of MyDSN.
Cn.open "dsn=mydsn;uid=sa;pwd=;d atabase=pubs"
Set rs = Cn.execute ("Select logo from pub_info where pub_id=0736")
Response.BinaryWrite RS ("logo")
Response.End
%>
*****************************************
Execute this ASP file to see the image you have in the database.
But it's going to be a little hard to deal with text and images at the same time:-(
For example: One enterprise's personnel management, the backstage database may use Sybase or the SQL Server and so on. (I use SQL Server here) when you need to use the Browse/server in the enterprise, that is, to view the employee's personal information in the browser, it is necessary to process the text information at the same time to use the skills of the image.
The problem is that when you display text messages, the content= "text/html" in the head of the HTML, and the display image must be content= "image/gif" or content= "Image/jpeg". Therefore, you can not use only an ASP file to the text information and images are processed, the solution is: with a separate ASP file processing image, and then in the processing of text information ASP file call this ASP file.
Here to introduce a my solution, I hope you can discuss together:
Environment: winnt4.0 SQL Server iis3.0
Database name: RSDA
Table Name: rsda_table
Objective: To identify the personnel of id=00001 from Rsda_table, including name, age and photo

First step: Create a query form rsda.htm:
**********************************
<body>
<form method Ost "action=" Search.asp ">
<p> Please enter the number: <input type= "text" name= "T1" size= "><input"
Type= "Submit" value= "submitted" Name= "B1" ><input type= "reset" value= "recovery" name= "B2" > </p>
</form>
</body>
***********************************
Step Two: Establish search.asp
***********************************
<meta http-equiv= "Content-type" content= "text/html;charset=gb2312"
<title> Query Results </title>
<body bgcolor=azure>

<%
Session ("rsda_id") =request.form ("T1") here I use a session variable to call again in the ASP file that processes the image
Temp_id=session ("rsda_id")
<font size=4 color=orangered> Query Result: </font>
<%set conntemp=server.createobject ("Adodb.connection")
Conntemp.open "Dsn=rsda;uid=sa;pwd=sa"
Set Rstemp=conntemp.execute ("SELECT * from rsda_table where rsda=" &temp_id& ")
%>
<% put headings on the table of field names
nobody= "Sorry!" In our database there is no information you are looking for! "%> judge whether there is this person
<%if Rstemp.eof then%>
<font size= "5" color=orangered> <%response.write (nobody)%> </font>
<%else%>
<div align= "Center"
<center>
<table border= "1" width= "73%" height= "399"
<tr>
<TD width= "21%" height= "align=" "Center" ><p align= "center" > name </td>
<TD width= "30%" height= "align=" "Center"
<font size=4 color=orangered><%=rstemp (0)%> </font> </td>
</td>
<tr>
<TD width= "21%" height= "><p align=" "Center" > Age </td>
<TD width= "30%" height= "align=" "Center"
<font size=4 color=orangered><%=rstemp (0)%> </font> </td>
</tr>
<tr>
<TD width= "49%" height= "146" rowspan= "3" colspan= "2"
</td> jpg.asp is the ASP file that we're going to set up to deal with images specifically
</tr>
</table>
</center> </div>
Rstemp.close
Set rstemp=nothing
Conntemp.close
Set conntemp=nothing
%>
</body>
***********************************
Step three: Create an ASP file (jpg.asp) for processing images.
***********************************
<%
Response.Expires = 0
Response.Buffer = True
Response.Clear

Open Database
Set conntemp = Server.CreateObject ("Adodb.connection")
Conntemp.open "Dsn=rsda;uid=sa;pwd=sa"

Change HTTP Header
Response.ContentType = "Image/jpeg" or "image/gif"

Get the picture

Temp_id=session ("rsda_id")
Set rs = Conntemp.execute ("Select photo from rsda_table where id=" ")
Response.BinaryWrite rs ("photo")
Session.Abandon
Response.End
%>
***************************



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.