Click to See Complete Forum and Search --> : Webpage URLs return image/JavaScript files


MarkE
05-06-2003, 04:25 PM
Sometimes I look at the source code of a webpage and I see that the sources for some of the image and external JavaScript files are URLs of server-side pages (like asp or cgi) with a query string at the end, and I wonder: how can they return an image or JavaScript file using a webpage file URL? I have also experienced links in the Microsoft (http://www.microsoft.com) website that are links to EXE (self-extracting) files through the use of page URLs.

Here is an example: go to http://www.easycounter.com/FreeCounter3.html and you will see that it tells you to use a webpage URL for a dynamically-changing image:



Step 2: Add the HTML below to your web pages, substituting values for PageID and Username. The PageID must be unique for each web page that you place the counter on. The PageID may contain letters, numbers, periods, and underscores; it may not contain spaces. All web pages must use the same Username.

<a href="http://www.easycounter.com/cgi-bin/link3.exe">
<img src="http://www.easycounter.com/cgi-bin/count3.exe?PageID,Username"
ismap border="0" width="88" height="31"></a><br>
<a href="http://www.easycounter.com">EasyCounter</a>

Example:

<a href="http://www.easycounter.com/cgi-bin/link3.exe">
<img src="http://www.easycounter.com/cgi-bin/count3.exe?index.html,JohnDoe"
ismap border="0" width="88" height="31"></a><br>
<a href="http://www.easycounter.com">EasyCounter</a>


By the way, in a query string, don't you need to have name-value pairs separated by = signs and & signs? (e.g. ...?x=hello&b=ddd&form=ii )
What is this page doing?

ChrisBrown
05-06-2003, 05:02 PM
Mark,

It is doing a QueryString, but look - the "," is the separator of the data, and the .exe or .cgi is simply just parsing the data and is looking for data in between the commas. VBScript works this way too, depending on the statement.

Bullschmidt
05-07-2003, 02:38 AM
Perhaps check this out:

Serving Dynamic Images from Static Web Pages - 5/24/2000
http://www.4guysfromrolla.com/webtech/052400-1.shtml

cmelnick
05-07-2003, 08:20 AM
What you have to remember about content being returned to your browser, is that it is all formated by the server side script or executable to be a format that your browser can interpret.

Basically, what is really happening when your browser loads the web page and gets to a line:
<img src="/pics/whatever.jpg">
is your browser says "I need to make another request to the server and ask for file 'whatever.jpg'." You send a file request for "http://www.wherever.com/pics/whatever.jpg".

On the server side, it sees an HTTP request for "/pics/whatever.jpg". The server says, "I know what a .jpg file is and I know how to send it back." And it starts sending the binary .jpg file back to the browser.

Now, for the instance of a .cgi or .exe page for an img src. On the browser side, it is identical. You just send a request for "http://www.wherever.com/cgi/pic_generator.exe?frank,10". Your browser thinks that it is going to be downloading a picture. It doesn't know the difference between a request for a .jpg and a .exe.

From the server side, howerver, it sees the request for "/cgi/pic_generator.exe" with query string "frank,10". Now the server says, "I know what a .exe file is, and I am supposed to execute it." At this point, cgi_generator.exe runs, and figures out what to do with the query string. The query string doesn't have to be any specific format (as in key1=value1&key2=value2), as long as the .exe file knows how to interpret it. The .exe file does its magic, and then outputs the binary data that is sent to the browser. This binary data is the data for an image, but instead of just reading in an image file, and sending it to the browser, it is generating the image file, and sending it to the browser.

cmelnick
05-07-2003, 08:52 AM
Here is an example of how an ASP file can return a binary file.


<%

' Querystring should be fldr=<current folder>&file=<desired download>
If Request.QueryString("file") <> "" Then
Dim filesys, baseFldr, extFldr, realFldr

Set filesys = Server.CreateObject("Scripting.FileSystemObject")
baseFldr = "D:\Webs\"
extFldr = Request.QueryString("fldr")

' Get filename
Dim dlFile, txtFile
dlFile = baseFldr & extFldr & "\" & Request.QueryString("file")

Dim bin, binStream

' Set binary type
bin = 1

' Create Stream and open
Set binStream = Server.CreateObject("ADODB.Stream")
binStream.Open

' Set binStream to binary, and load desired file
binStream.Type = bin
binStream.LoadFromFile dlFile

' Set header for attachment (ie: "Save As" dialog)
Response.AddHeader "Content-Disposition","attachment;filename=" & Request.QueryString("file")

' Write the binary file to browser
Response.BinaryWrite binStream.read

' Clear out binStream
Set binStream = Nothing

End If
%>


* Note: Using the ADODB.Stream object is an easy way to read binary data since ASP does not have any built in procedures to read binary data.