views:

335

answers:

3

hi,

i'm displaying an image like this:

<img src='counter.asp'>

counter.asp is doing a hitcounter do determine how often the image was displayed (i'll replace it with a modrewrite url).

the problem: in the counter.asp script i need to send the actual .jpg image to the browser, how could this be done? i suppose i need to load the image through FSO then send it using Response.BinaryWrite - any ideas?

thanks

A: 

FSO cannot load a binary file, only text. You will need to use a 3th party component.

ZippyV
The answer below mentioning ADODB.Stream *should* have been the accepted one.
thomask
A: 

you can just redirect your counter.asp to the image you want..

<%
response.redirect("/virtual/path/to/yourimage.jpg")
%>
Gaby
+1  A: 

To read and output binary you can simply use the ADODB.Stream object.

See the ADODB.Stream MSDN Library:
http://msdn.microsoft.com/en-us/library/ms675032(VS.85).aspx

Here's an example I found from Experts Exchange as well:

Function ReadBinaryFile(strFileName) 
        on error resume next 
        Set oStream = Server.CreateObject("ADODB.Stream") 
        if Err.Number <> 0 then 
                ReadBinaryFile=Err.Description 
                Err.Clear 
                exit function 
        end if 
        oStream.Type = 1  
        oStream.Open 

        oStream.LoadFromFile strFileName 
        if Err.Number<>0 then 
                ReadBinaryFile=Err.Description 
                Err.Clear 
                exit function 
        end if 
        ReadBinaryFile=oStream.Read 
        oStream.Close 
        set oStream = nothing 
        if Err.Number<>0 then ReadBinaryFile=Err.Description 
End Function  
Micah