用Adodb.Stream将以二进制方式保存在数据库中的文件保存到硬盘
对于上传的数据库中的文件有的时候需要保存成硬盘上的文件,下面的代码以ACCESS数据库为例,演示怎样通过Adodb.Stream将文件保存到硬盘
表:Demo的结构
=======================================
id: 自动编号
filename:文本
data: OLE 对象
代码
=======================================
<%
Dim Conn,ConnStr,Rs,Sql,MyStream
ConnStr="DBQ=" + Server.Mappath("Demo.mdb") + ";DRIVER={Microsoft Access Driver (*.mdb)};"
Set Conn = Server.CreateObject("Adodb.Connection")
Conn.Open ConnStr
Sql = "select * from demo where id=1"
Set Rs = Server.CreateObject("Adodb.RecordSet")
Rs.Open Sql,Conn,1,3
Set MyStream=Server.CreateObject("Adodb.Stream")
MyStream.Type = 1
MyStream.Open
MyStream.Write Rs("data").GetChunk(rs("data").ActualSize-78)
MyStream.SaveToFile "c:\" & Rs("fileName")
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
%>
表:Demo的结构
=======================================
id: 自动编号
filename:文本
data: OLE 对象
代码
=======================================
<%
Dim Conn,ConnStr,Rs,Sql,MyStream
ConnStr="DBQ=" + Server.Mappath("Demo.mdb") + ";DRIVER={Microsoft Access Driver (*.mdb)};"
Set Conn = Server.CreateObject("Adodb.Connection")
Conn.Open ConnStr
Sql = "select * from demo where id=1"
Set Rs = Server.CreateObject("Adodb.RecordSet")
Rs.Open Sql,Conn,1,3
Set MyStream=Server.CreateObject("Adodb.Stream")
MyStream.Type = 1
MyStream.Open
MyStream.Write Rs("data").GetChunk(rs("data").ActualSize-78)
MyStream.SaveToFile "c:\" & Rs("fileName")
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
%>
- 没有相关文章
- 没有评论