代码全给你:
<form name="mainForm" enctype="multipart/form-data"这个Form属性是得到上传的数据的关键 action="process.asp" method=post>
<table width="57%" height="84" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" colspan="2"><div align="center">
<input type=file name=mefile>
</div></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type=submit name=ok value="上传">
</div></td>
</tr>
</table>
</form>
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("../db/db.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
%>
<script language="javascript">
alert('图片上传成功!')
window.location.href="xinwen.asp"
</script>
写入数据库的图片显示:
<img src="showimg.asp?id=<%=rs3("id")%>" width="138" height="106" />
showimg.asp代码:
<%
set connGraph=server.CreateObject("ADODB.connection")
connGraph.ConnectionString="driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("db/db.mdb") & ";uid=;PWD=;"
connGraph.Open
id=request("id")
set rec=server.createobject("ADODB.recordset")
strsql="select img from images where id=" & trim(request("id")) img字段是你的长二进制类型数据,就是你的图片信息。
rec.open strsql,connGraph,1,1
Response.ContentType = "image/*"
' 在输出到浏览器之前一定要指定Response.ContentType = "image/*",以便正常显示图片
Response.BinaryWrite rec("img").getChunk(7500000)
rec.close
set rec=nothing
set connGraph=nothing
%>