图片上传数据库的代码

图片上传数据库的代码

dim rs 
dim formsize,formdata,bncrlf,divider,datastart,dataend,mydata
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)


Sqlcmd="SELECT * from pic   where idname='"&session("idtu")&"'" 
    set res=conn.Execute(Sqlcmd)
    if res.EOF Then

sql="select * from pic order by id desc"

set rs=conn.execute(sql)
id=rs("id")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "pic",conn,3,2
rs.addnew
rs("big").appendchunk mydata
rs("idname")=session("idtu")
rs.update
set rs=nothing
set conn=nothing
response.redirect "sendphoto.asp"
    else
       

end if

从数据库中读出代码

id=request("id")
Set conn = Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("data.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="&DBPath
set rs=server.createobject("ADODB.recordset") 
sql="select * from pic where id="&id
rs.open sql,conn,1,1 
Response.ContentType = "image/jpeg" 
Response.BinaryWrite rs("big")
rs.close 
set rs=nothing 
set connGraph=nothing

留下回复