明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

ASP中從數(shù)據(jù)庫讀取二進(jìn)制文件數(shù)據(jù)代碼

[摘要]<%driver_name1="DRIVER=Microsoft Access Driver (*.mdb); DBQ=D:\數(shù)據(jù)庫\TREE.MDB" '根目錄下數(shù)據(jù)庫打開語句 dim search,rs,j search="select *...

<%
driver_name1="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=D:\數(shù)據(jù)庫\TREE.MDB"    '根目錄下數(shù)據(jù)庫打開語句

  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 "錯(cuò)誤:找不到該文件"
    response.end
  end if

'設(shè)置文件的大小及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
%>