ASP upload image function of another implementation (OLE Object) _asp Foundation

Source: Internet
Author: User
The last mention of the upload image is adopted by the old Farmer's development of the component-free upload. The upload process is to save the picture to the specified folder, while saving the path to the database field. The display picture is displayed according to the Path field in the database table. Of course, about the management of pictures, such as delete: only delete the path, the actual picture needs to be deleted by the FSO.

Is there a situation where a picture is saved directly as the value of a field. The operation of the picture is as skilled as the operation of the data field. The answer is yes, just the type of the field is set to 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 that are created in other programs. Binary Data。 OLE objects can be linked or embedded inA field in a Microsoft Access table.

First, design database Testimg.mdb

To facilitate debugging, design the table Imgurl, where two fields: ID (AutoNumber, Keywords), 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, provides the upload picture the form page 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 data and add a 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"
%>



V. Extract the contents of the Picture field in the database table to do the display 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
%>



Six, display the picture 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.