用纯ASP代码实现图片上传并存入数据库中

接下来,我们要在process.asp中对从浏览器中获取的数据进行必要的处理,因为我们在process.asp中获取到的数据不仅仅包含了我们想要的上传上来的图片的数据,也包含了其他的无用的信息,我们需要剔除冗余数据,并将处理过的图片数据保存到数据库中,这里我们以Access97为例。具体代码如下(process.asp):

< %

response.buffer=true

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 connGraph=server.CreateObject("ADODB.connection")


connGraph.ConnectionString="driver={Microsoft Access Driver (*.mdb)};DBQ=" &


server.MapPath("images.mdb") & ";uid=;PWD=;"


connGraph.Open


set rec=server.createobject("ADODB.recordset")


rec.Open "SELECT * FROM [images] where id is null",connGraph,1,3


rec.addnew


rec("img").appendchunk mydata


rec.update


rec.close


set rec=nothing


set connGraph=nothing


% >