The first weight: Single picture is not new, there is no new problem, but there are also a lot of tutorials online, but most is a fish, not to teach people to fish, have a hard information collection, thinking, debugging , Organize, I basically made this problem from principle. Now, based on my own understanding, I explain it on the basis of the example program, I hope to be able to have some netizens (more than me, :-)) Helped. Please refer to the unhealthy or bad of yourself. The use of Stream objects in the program refers to the "State HTTP Upmit Prorsion 2.0" in the code, which is a sincere thanks to Daoxiang Old farmers and Liang's fear. I want to step by step. Tell a simple one today, and a single image file is saved to the database. This example includes three ASP files and a database (a table), all in the same directory. 1, TBLIMAGE table structure (Access 2000) SN Auto Number Serial Number Content-Type Text Picture Type Image Ole Object Image Data 2, SimpleImageTodata.asp: Upload Form and Save Pictures to Database Code, Main Files.
<% @ Language = vbscript%> <% option explicit%> <% 'from a full path to default file name function getFileNameFromPath (StrPath) getFileNameFromPath = MID (StrPath, Instrrev (strpath, "/") 1) end function' Define database connection string DIM CNSTR CNSTR = "driver = {Microsoft Access Driver (* .mdb)}; DBQ =" & Server.mAppath ("./ Upload.mdb")%>
Upload picture display picture
Br> "Scome.Position = POSB 1 scrosb-2 sgo.position = 0 sgo.type = 2 sgo.charset =" gb2312 "strdata = sgo.readtext sgo.close 'response.write strdata & "
AdoDb.connection ") CN.Open CNSTR SET RS = Server.createObject (" AdoDb.Recordset ") SQL =" Select * from tblimage "RS.Open SQL, CN, 1, 3 rs.addnew rs.fields (" Content- Type "). Value = strcontenttype rs.fields (" image "). Appendchunk strdata rs.Update = nothing cnclose set cn = Nothing response.write" The picture saved successfully! "&"
"Else Response.write" no upload picture! "&"
"end if set sg = nothing screen.close set screen = nothing else%>