纯ASP上传图像文件到数据库的最佳例子

2018-09-06 10:44

阅读:559

  getfile.htm
-------------------------


















savetodb.asp
----------------------------------
<%

Response.Buffer = TRUE
Response.Clear
byteCount = Request.TotalBytes

RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject(Scripting.Dictionary)

BuildUploadRequestRequestBin

email = UploadRequest.Item(email).Item(Value)

contentType =UploadRequest.Item(blob).Item(ContentType)
filepathname = UploadRequest.Item(blob).Item(FileName)
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,))
picture = UploadRequest.Item(blob).Item(Value)

Response.binaryWrite picture

set objCn = server.createobject(adodb.connection)
set objRst = server.createobject(adodb.recordset)
objCn.Open upload
objrst.Open pic, objcn, 1,3,2
objrst.addnew
objrst.fields(filename)=filename
objrst.fields(type)=gif

objrst.fields(what).appendchunk picture
objrst.update

objrst.close

objCn.close
set objrst=nothing
set objcn = nothing
%>
<!--#include file=upload.asp-->

showpic.asp
----------------------------------------
<%
set objCn = server.createobject(adodb.connection)
set objRst = server.createobject(adodb.recordset)
objCn.Open upload
objrst.Open select what from pic where id= request(id), objcn

if not objrst.eof then
response.binarywrite objrst(what)
end if

objrst.close
objCn.close
set objrst=nothing
set objcn = nothing
%>


upload.asp
-------------------------------------------
<%
Sub BuildUploadRequest(RequestBin)
Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
Get all data inside the boundaries
Do until (boundaryPos=InstrB(RequestBin,boundary getByteString(--)))
Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject(Scripting.Dictionary)


评论


亲,登录后才可以留言!