2004/07/29 | 图片的上传并存入数据库
类别(Other) | 评论(0) | 阅读(165) | 发表于 10:08
不多说了 只给出源文件
pic.asp:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body>
<form name="form1" enctype="multipart/form-data" method="post" action="savepic.asp">
<input type="file" name="file">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
savepic.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)
accessdb="image.mdb"
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)
set rs=server.createobject("ADODB.recordset")
sql="select img from images"
rs.open sql,cn,1,3
rs("img").appendchunk mydata
rs.update
rs.close
set rs=nothing
%>
<a href="showpic.asp">showpic</a>
showpic.asp:
<%
accessdb="image.mdb"'数据库名
cn="DRIVER={Microsoft Access Driver (*.mdb)};"'
cn=cn & "DBQ=" & server.mappath(accessdb)
set rs=server.createobject("ADODB.recordset")
sql="select img from images where id=3"
rs.open sql,cn,1,3
Response.ContentType="image/jpeg"
Response.BinaryWrite rs("img").getChunk(7500000)
rs.close
set rs=nothing
%>
<img src="showpic.asp">
0

评论Comments

日志分类
首页[185]
Flash[123]
ColdFusion[2]
Flex[2]
FlashMedia[3]
RIA[4]
Other[43]
Python[0]
Design[8]