ndfweb.cn

ASP使用ADODB.Stream读取二进制文件


2009-04-13 09:55:53 (6766)


ASP使用ADODB.Stream读取二进制文件
下面的函数是ASP读取二进制文件的方法之一,我认为比较方便
<%
Function ReadBinaryFile(FileName)  
 Const adTypeBinary = 1  
 'Create Stream object  
 Dim BinaryStream  
 Set BinaryStream = CreateObject("ADODB.Stream")  
 'Specify stream type - we want To get binary data.  
 BinaryStream.Type = adTypeBinary         
 'Open the stream  
 BinaryStream.Open         
 'Load the file data from disk To stream object  
 BinaryStream.LoadFromFile FileName         
 'Open the stream And get binary data from the object  
 ReadBinaryFile = BinaryStream.ReadEnd
Function

%>
使用举例,读取gif文件,显示在浏览器中
<%
Dim path, gifdata   
' Locate the file on disk   
path = server.mappath("/images/someImage.gif")   
' Read the GIF image data  
gifdata = ReadBinaryFile(path)       
' Send the GIF image to the browser  
'Response.ContentType = "image/gif"  
'Response.Buffer = True  
'Response.Clear  
'Response.BinaryWrite gifdata  
'Response.Flush
%>

了解更多请访问:http://www.ndfweb.cn/news-283.html
  NDF俱乐部
  国际域名注册
  建站咨询
合作伙伴:万网 | 新网 | 新网互联 NDF网站建设淘宝店 | 实用工具 | 外貿網站建設 | 联系我们
鲁公网安备 37110202000336号 鲁ICP备2021027697号-1 Sitemap - RSSRSS订阅