ASP + ACCESS upload pictures to the database and read the picture out of the database display implementation (detailed version)

Source: Internet
Author: User
Tags ole

Implementation of ASP uploading image to database function

Generic no-component upload class, the upload process is to save the picture to the specified folder, at the same time save the path to the database field. Show The picture is displayed according to the path field in the Database table. Of course, about the management of the image , such as delete: only delete the path, the actual picture needs to be based on the path through the FSO to delete ... Is there a situation where the picture is saved directly as a field value? The operation of the picture is as familiar as the operation of the data field. The answer is yes, just set the type of the field as an OLE object

Knowledge Points: OLE object fields are used to store data such as Microsoft Word or Microsoft EXCEL documents, pictures , sounds, and other types of binary data that are created in other programs. An OLE object can be linked or embedded in a field in a Microsoft Access table.

First, Design database Testimg.mdb

For ease of debugging, design table Imgurl, where two fields: ID (autonumber, keyword), img (OLE object)

Second, the connection database file conn. ASP

<%
Db_path= "Testimg.mdb"
Set Conn=server. CreateObject ("Adodb.connection")
connstr= "Driver={microsoft Access driver (*.mdb)};d bq=" &server. MapPath (Db_path)
Conn.Open ConnStr
%>

Third, provide a form page to upload pictures upload.html

<form action= "Upload. asp"method=" post "enctype=" Multipart/form-data ">
<input type= "File" name= "Imgurl" >
<input type= "Submit" Name=ok value= "OK" >
</form>

Iv. accept the data and add the record page upload. ASP

<!--#include file= "Conn. ASP--
<%
Formsize=request.totalbytes
Formdata=request.binaryread (Formsize)
BNCRLF=CHRB (&CHRB) (10)
Divider=leftb (FORMDATA,CLNG (INSTRB (FORMDATA,BNCRLF))-1)
DATASTART=INSTRB (FORMDATA,BNCRLF&BNCRLF) +4
DATAEND=INSTRB (Datastart+1,formdata,divider)-datastart
MYDATA=MIDB (Formdata,datastart,dataend)
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open "SELECT * from Imgurl", conn,3,3
Rs.addnew
RS ("img"). AppendChunk MyData
Rs.update
Rs.close
Set rs=nothing
Set conn=nothing
Response.Redirect "index. ASP"
%>

Extract the contents of the Picture field in the Database table to display the Picture page showimg. ASP

<!--#include file= "Conn. ASP--
<%
Set Rs=server.createobject ("Adodb.recordset")
Sql= "SELECT * from Imgurl where id=" &trim (Request ("id"))
Rs.Open sql,conn,1,1
Response.contenttype= "image/*"
Response.BinaryWrite RS ("img"). GetChunk (8000000)
Rs.close
Set rs=nothing
Set conn=nothing
%>

Vi. Display The index of the picture . ASP

<!--#include file= "Conn. ASP--
<%
Strsql= "SELECT * from Imgurl"
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open strsql,conn,1,1
Do Until rs.eof
WHATID=RS ("id")
%>
asp?id=<%=whatid%> ">

<%
Rs.movenext
Loop

%>

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.