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