网站地图    收藏   

主页 > 入门引导 > 网站问答 >

图像图表_编程10000问_

来源:自学PHP网    时间:2015-02-03 17:41 作者: 阅读:

[导读] 图像图表...

NEWSZW_HZH_BEGIN-->

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

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]

NEWSZW_HZH_END-->

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论