发布网友 发布时间:2024-09-27 01:00
共1个回答
热心网友 时间:2024-10-01 19:36
1.数据库设计:
名称:images.mdb
表:images
字段:id 自动编号且为主键; images OLE对象
2.数据库连接文件conn.asp:
程序代码
<%
db="images.mdb" '数据库存放目录
on error resume next
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath(db)
if err then
err.clear
set conn = Nothing
response.write "数据库连接出错,请检查conn.asp中的连接字符串。"
response.end
end if
function CloseDB
Conn.Close
set Conn=Nothing
End Function
%>
3.upload.html文件:
程序代码
<form action="upload.asp" method="post" enctype="multipart/form-data">
<input type="file" name="images">
<input type="submit" name=ok value="上传">
</form>
4.upload.asp文件:
程序代码
<!--#include file="conn.asp"-->
<%
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 rs=server.createobject("ADODB.recordset")
rs.open "Select * FROM images",conn,3,3
rs.addnew
rs("images").AppendChunk myData
rs.update
rs.close
set rs=nothing
set conn=nothing
response.redirect "index.asp"
%>
5.显示图片文件show.asp:
程序代码
<!--#include file="conn.asp"-->
<%
set rs=server.createobject("ADODB.recordset")
sql="select * from images where id="&trim(request("id"))
rs.open sql,conn,1,1
Response.ContentType="image/*"
Response.BinaryWrite rs("images").getChunk(8000000)
rs.close
set rs=nothing
set conn=nothing
%>
6.首页index.asp:
程序代码
<!--#include file="conn.asp"-->
<%
strsql="select * from images"
set rs=server.createobject("ADODB.recordset")
rs.open strsql,conn,1,1
do until rs.eof
id=rs("id")
%>
<img src="show.asp?id=<%=id%>">
<%
rs.movenext
loop
%>
7.完成。呵呵
鉴于好多个网友都说不能显示,本人今天再次试了以下.明显可以.现在把上面的文件打包起来,提供下载.希望能给您带来便利.
点击下载此文件
参考资料:http://www.linglihu.com/article.asp?id=80