Easily upload pictures to the database
I have been thinking about writing a program by myself for a long time, but since I don’t want to write about me, I just happened to have time today, so it’s easy to know after writing this small program. I won’t say much, so I’ll start here:
Let's do an upload. The fields in the database are automatically numbered by id. Big field type is OLE. Hehe, that is the simple field.
Uppic.asp upload program name
<%
dimrs
dimformsize, formdata,bncrlf,divider,datastart,dataend,mydata
formsize=request.totalbytes' Get the size sent by the client
formdata=request.binaryread(formsize)'Convert the data sent by the customer into binary production
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)'The above is to obtain the binary data of the image in total
%>
<!--#includefile="conn.asp"-->
<%
sql="select*frompicorderbyiddesc"
Setrs=Server.CreateObject("ADODB.Recordset")
rs.Opensql,conn,3,2
rs.addnew
rs("big").appendchunkmydata' added to the database
rs.update
setrs=nothing
setconn=nothing
%>
Next is to display the picture
display.asp
<!--#includefile="conn.asp"-->'Everyone knows this, it is a program connected to the database.
<%
id=request("id")
setrs=server.createobject("ADODB.recordset")
sql="select*frompicwhereid="&id
rs.opensql,conn,1,1
Response.ContentType="text/html"' can also use the format of displaying the picture.
'Response.ContentType="image/gif" is displayed as gif
'Response.ContentType="image/jpg" is displayed in jpg
Response.BinaryWriters("big")' Show image
rs.close
setrs=nothing
setconnGraph=nothing
%>