The uploaded image mentioned last time was uploaded without components developed by Daoxiang Laonong. The upload process is to save the image to the specified folder first, and at the same time save the path to the database field. The display image is displayed according to the path field in the database table. Of course, related to the management of pictures, such as deletion: only the path is deleted, and the actual picture needs to be deleted through FSO according to the path...
Is there a situation where the image is saved directly as a field's value. Operations on pictures are as proficient as operating data fields. The answer is yes, just set the type of the field to an OLE object
Knowledge Point: The OLE object field is used to store data for documents, pictures, sounds, and other types of binary data created in other programs. OLE objects can be linked or embedded into fields in Microsoft Access tables.
1. Design database testimg.mdb
For easy debugging, design table imgurl, with two fields: id (auto 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 %> |
3. Provide the form page upload.html for uploading pictures
<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 record page upload.asp
<!--#include file="conn.asp"--> <% formsize=request.totalbytes formdata=request.binaryread(formsize) bncrlf=chrB(13)&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" %> |
5. Extract the content of the picture field in the database table to display the picture page showimg.asp