2

I'm displaying an image like this:

<img src='counter.asp'>

counter.asp is doing a hit-counter 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, and then send it using Response.BinaryWrite - any ideas?

Toothbrush
  • 2,080
  • 24
  • 33
Fuxi
  • 7,611
  • 25
  • 93
  • 139

3 Answers3

10

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  
Sir CodesALot
  • 946
  • 1
  • 15
  • 16
2

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

<%
response.redirect("/virtual/path/to/yourimage.jpg")
%>
Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
-5

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

ZippyV
  • 12,540
  • 3
  • 37
  • 52