Another Implementation of the ASP image upload function (OLE object)

Source: Internet
Author: User

The uploaded image was a component-less upload developed by O & M elders. During the upload process, the image is saved to the specified folder, and the path is saved to the database field. The displayed image is displayed based on the path field in the database table. Of course, for image management, such as deleting: only the path is deleted, and the actual image needs to be deleted through FSO according to the path ......

Is there a situation where the image is saved directly as a field value. Operations on images are like operations on data fields. The answer is yes, just set the field typeOLE object

Knowledge Point: OLE object fields are used to store data such as Microsoft Word or Microsoft Excel documents, images, and sounds, andProgramOther typesBinary data. OLE objects can be linked orEmbeddedField in the Microsoft Access Table.

I. design the database testimg. MDB

Design tables for ease of debuggingImgurlTwo fields: ID (automatic number, keyword), IMG (OLE object)

2. Connect to the database file conn. asp

<%
Db_path = "testimg. mdb"
Set conn = server. Createobject ("ADODB. Connection ")
Connstr = "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & server. mappath (db_path)
Conn. Open connstr
%>

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>

4. Accept data and add the record page upload. asp

<! -- # Include file = "conn. asp" -->
<%
Formsize = request. totalbytes
Formdata = request. binaryread (formsize)
Bncrlf = chrb (13) & chrb (10)
Divider = leftb (formdata, clng (partition B (formdata, bncrlf)-1)
Datastart = instrb (formdata, bncrlf & bncrlf) + 4
Dataend = Consumer B (datastart + 1, formdata, divider)-datastart
Mydata = midb (formdata, datastart, dataend)
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open "select * From imgurl", Conn, 3
Rs. addnew
RS ("IMG"). AppendChunk mydata
Rs. Update
Rs. Close
Set rs = nothing
Set conn = nothing
Response. Redirect "index. asp"
%>

5. Extract the image field from the database table to display the showimg. asp image page.

<! -- # 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
%>

6. display the image index. 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 ")
%>
">

<%
Rs. movenext
Loop %>

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.