当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP中从数据库读取二进制文件数据代码

ASP
ASP简单入门教程(2):ASP环境配置
ASP简单入门教程(3):ASP语法
ASP简单入门教程(4):ASP变量
ASP简单入门教程(5):ASP子程序
HTTP 500 - 内部服务器错误(补充内容)
ASP教程:IIS中配置多站点
ASP实例教程:Content Rotator (ASP 3.0)
ASP实例教程:Content Linking组件
ASP实例教程:Browser Capabilities组件
ASP实例教程:AdRotator组件
ASP实例教程:Dictionary对象
ASP实例教程:File对象
ASP实例教程:Drive对象
ASP实例教程:TextStream对象
关于学习ASP的20个测试题目
ASP实例教程:Server对象
ASP实例教程:Session对象
ASP实例教程:用户信息和服务器
asp教程:解决IIS安装问题
ASP网站数据库被挂木马的处理办法

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 150 ::
收藏到网摘: n/a

 

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