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

ASP
ASP漏洞及安全建议(3)
ASP漏洞及安全建议(4)
实现聊天室的悄悄话功能(上)
实现聊天室的悄悄话功能(中)
用ASP实现悄悄话的功能
《 优化你的ASP程序 》
让ASP应用系统成为跨平台的应用系统
让ASP应用系统成为跨平台的应用系统(2)
使用ASP加密算法加密你的数据(一)
使用ASP加密算法加密你的数据(二)
用ASP制作个性化的调查板
asp+语法介绍(二)---书写我们的第一个asp+ 文件
asp+语法介绍(一)
asp+语法介绍(三)----asp+的服务器端编程初步
asp+语法介绍(四)----asp+的服务器端编程进介
asp+语法介绍(五)----asp+的服务器端编程控件篇
sp+语法介绍(六)----数据库篇
用ASP和VBScript上载文件(一)
用ASP和VBScript上载文件(二)
解析正则表达式(原创)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 55 ::
收藏到网摘: 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
%>