Generally, no-component upload class saves the image to the specified folder and saves the path to the database fields. 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. It only sets the field type as an OLE object.
Knowledge Point: OLE object fields are used to store data such as Microsoft Word or Microsoft Excel documents, images, and sounds, andProgramOther types of binary data created in. OLE objects can be linked or embedded into fields in the Microsoft Access Table.
I. design the database testimg. MDB
To facilitate debugging, design the imgurl table, including two 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 (Using B (formdata, bncrlf )) - 1 )
Datastart = Using B (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"
% >
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 " )
% >
< IMG SRC = " Showimg. asp? Id = <% = Whatid %> " >
< %
Rs. movenext
Loop % >