1
2driver_name1="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=D:\数据库\TREE.MDB" '根目录下数据库打开语句
3
4dim search,rs,j
5search="select * from Files where ID=" & request.querystring("ID")
6set my_conn=server.CreateObject ("adodb.connection")
7my_conn.open driver_name1
8set rs=Server.CreateObject("ADODB.Recordset")
9rs.Open search,my_conn,1,3
10if rs.bof or rs.eof then
11response.write "错误:找不到该文件"
12response.end
13end if
14
15'设置文件的大小及MIME类型
16Function SetForDisplay(field, contentType)
17contentType = LCase(trim(contentType))
18nFieldSize = field.ActualSize
19bytes = field.GetChunk(nFieldSize)
20Session("Bytes") = bytes
21Session("Type") = contentType
22End Function
23
24SetForDisplay RS("File"),rs("FileType")
25'Response.AddHeader "Content-Disposition", "attachment; filename=" & rs("FileName")
26response.contentType = Session("Type")
27response.BinaryWrite Session("Bytes")
28Session("Type") = ""
29Session("Bytes") = ""
30
31set rs=nothing
32my_conn.close
33set my_conn=nothing
ASP中从数据库读取二进制文件数据代码
comments powered by Disqus