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
%>