ASP中从数据库读取二进制文件数据代码

王朝asp·作者佚名  2006-01-09
宽屏版  字体: |||超大  

<%

driver_name1="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=D:\数据库\TREE.MDB" '根目录下数据库打开语句

dim search,rs,j

search="select * from Files where ID=" & request.querystring("ID")

set my_conn=server.CreateObject ("adodb.connection")

my_conn.open driver_name1

set rs=Server.CreateObject("ADODB.Recordset")

rs.Open search,my_conn,1,3

if rs.bof or rs.eof then

response.write "错误:找不到该文件"

response.end

end if

'设置文件的大小及MIME类型

Function SetForDisplay(field, contentType)

contentType = LCase(trim(contentType))

nFieldSize = field.ActualSize

bytes = field.GetChunk(nFieldSize)

Session("Bytes") = bytes

Session("Type") = contentType

End Function

SetForDisplay RS("File"),rs("FileType")

'Response.AddHeader "Content-Disposition", "attachment; filename=" & rs("FileName")

response.contentType = Session("Type")

response.BinaryWrite Session("Bytes")

Session("Type") = ""

Session("Bytes") = ""

set rs=nothing

my_conn.close

set my_conn=nothing

%>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有