Display JPEG with Response.BinaryWrite

I display the image as follows:

<img src='counter.asp'> 

counter.asp does a hit-counter to determine how often the image is displayed (I will replace it with the modrewrite URL).

Problem: in counter.asp script I need to send the actual .jpg image to the browser. How can I do that? I suppose I need to upload an image via FSO and then send it using Response.BinaryWrite - any ideas?

+2
source share
3 answers

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

-4
source

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

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

Here is an example I found from Expert Exchange:

 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 
+10
source

you can simply redirect your counter.asp to the desired image.

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

All Articles