ndfweb.cn

ASP使用ADODB.Stream讀取二進製文件


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



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网站建设淘宝店 | ICO图标在线生成 | 外贸网站建设 | 联系我们
©2007-2025 NDF Corporation 鲁ICP备08005967号 Sitemap - RSSRSS订阅