7月112014
将数据库内二进制数据导出为图片
- <%
- set conn = server.createobject("adodb.connection")
- conn.open Application("sql")
- %>
- <%
- '从数据库中将二进制文件导出到硬盘上
- 'set rs=server.createobject("adodb.recordset")
- 'sql="SELECT * FROM news WHERE id=12219"
- 'set rs = conn.execute("SELECT * FROM news WHERE id=12219")
- 'dim stream
- 'rs.open sql,conn,1
- 'set stream = server.createObject("adodb.stream")
- '参数为1以二进制类型模式打开
- 'stream.type = 1
- 'stream.open
- 'stream.write rs("newstitle")
- '参数为1,不覆盖,2覆盖
- 'mc=rs("id") &".txt"
- 'stream.saveToFile "d:\newshui\files\"&mc, 2
- 'stream.close
- 'picer=rs("newspic")
- 'Set fso = Server.CreateObject("Scripting.FileSystemObject")
- 'Set objStream = fso.OpenTextFile(Server.mappath("\huiyizhanlan\template_meeting_wiew.htm"))
- 'newscontent=objStream.Readall
- 'newscontent=replace(newscontent,"{meetingname}",title)
- 'newscontent=replace(newscontent,"{fatime}",now())
- 'newscontent=replace(newscontent,"{huitype}",leixing)
- 'newscontent=replace(newscontent,"{lianxiren}",lianxiren)
- 'newscontent=replace(newscontent,"{liandianhua}",lianxidianhua)
- 'newscontent=replace(newscontent,"{huiyizhuanti}",zhuanti1)
- 'newscontent=replace(newscontent,"{starttime}",kstime)
- 'newscontent=replace(newscontent,"{endtime}",jstime)
- 'newscontent=replace(newscontent,"{address}",didian)
- 'newscontent=replace(newscontent,"{liulanrenshu}",fname)
- 'newscontent=replace(newscontent,"{zhubandanwei}",unitcomp)
- 'newscontent=replace(newscontent,"{chengbandanwei}",chengbandanwei)
- 'newscontent=replace(newscontent,"{neirong}",neirong)
- 'objStream.close
- 'If not fso.FolderExists(Server.mappath("\huiyizhanlan\html")) Then
- 'Set f = fso.CreateFolder(Server.mappath("\huiyizhanlan1\html"))
- 'set f=nothing
- 'end if
- 'rs.close
- 'set rs=nothing
- 'conn.close
- 'set conn=nothing
- 'response.redirect "files/"&mc
- %>
- <%
- '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 top 10 * FROM news WHERE newspic is not null"
- Set Rs = Server.CreateObject("Adodb.RecordSet")
- Rs.Open Sql,Conn,1,3
- 'Set MyStream=Server.CreateObject("Adodb.Stream")
- 'MyStream.Type = 1
- 'MyStream.Type = 2
- 'MyStream.Open
- 'MyStream.Write Rs("newspic").GetChunk(rs("newspic").ActualSize-78)
- 'MyStream.SaveToFile "d:\newshui\files\" & Rs("id")&".jpg"
- 'response.Write rs("newspic")
- for i=1 to rs.recordcount
- Response.BinaryWrite rs("newspic")&"<br>"&i&""
- if rs.eof then exit for end if
- next
- rs.movenext
- 'set stream = server.createObject("adodb.stream")
- '参数为1以二进制类型模式打开
- 'stream.type = 2
- 'stream.open
- 'stream.write rs("newspic")
- '参数为1,不覆盖,2覆盖
- 'mc=rs("id") &".jpg"
- 'stream.saveToFile "d:\newshui\files\"&mc, 2
- 'stream.close
- 'Set fso = Server.CreateObject("Scripting.FileSystemObject")
- 'Set objHtml = fso.CreateTextFile(Server.mappath("\files\1.jpg"))
- 'objHtml.WriteLine request.binaryread(rs("newspic"))
- 'objHtml.close
- 'set fso=nothing
- Rs.Close
- Set Rs = Nothing
- Conn.Close
- Set Conn = Nothing
- %>
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!