欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

图像图表

程序员文章站 2022-04-15 09:19:06
如何把图片上传到数据库中并显示出来?upload.htm' 上传页面.

如何把图片上传到数据库中并显示出来?

upload.htm

' 上传页面.

<html>

<body>

<p align="center">千花飞舞之图片上传</p>
<center>
   <form name="mainform" enctype="multipart/form-data"

' 这个form属性是得到上传的数据的关键.
action="process.asp" method=post>
    <input type=file name=mefile><br>
   <input type=submit name=ok value="上传">
   </form>
</center>
</body></html>

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
%>
 

showimg.asp

' 显示图片.
<%
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")
strsql="select img from images where id=" & trim(request("id"))
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
%>

[1]