当前位置: 移动技术网 > IT编程>开发语言>.net > 纯ASP上传图像文件到数据库的最佳例子

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

2018年10月22日  | 移动技术网IT编程  | 我要评论

我想和你唱第二季时间,2012亚洲十帅,柏林危机 空难电影

getfile.htm
-------------------------
<html>

<head>
<title>保存图片到</title>
</head>

<body>
<b>

<p></b>你可以找个图片试试,保存完毕后会有提示</p>

<form method="post" enctype="multipart/form-data" action="savetodb.">
  <p>email : <input name="email" value="wangcq@sina.com" size="20"><br>
  picture : <input type="file" name="blob"><br>
  <input type="submit" name="enter"> </p>
</form>
</body>
</html>

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

response.buffer = true
response.clear
bytecount = request.totalbytes

requestbin = request.binaryread(bytecount)
dim uploadrequest
set uploadrequest = createobject("scripting.dictionary")

builduploadrequest  requestbin

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.contenttype = contenttype
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
response.write "<a href=showpic.asp?id=" & objrst("id") & ">第" & objrst("id") & "个图片。</a>"
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")

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网