Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how display a GIF image using asp? 3

Status
Not open for further replies.

wvdba

IS-IT--Management
Jun 3, 2008
465
US
Hi.
i have an image (owc.gif) that i need to display on an asp page. i know i can use html to display it. but, i have been told to use asp to display this image.
any suggestions?
thanks.
 
Pure asp like this:
Code:
<%
response.write "<img src=owc.gif>"
%>

it's so obvious that i presume you want something else?!
 
thanks foxbox.
this just simply writes an html statement, which i have been told not to do. i have to use binarywrite so the image file name is not seen in the html code.
thanks.
 
File1.asp
Code:
<img src="image.asp">


Image.asp
Code:
<%
  Dim objStream
  Set objStream = Server.CreateObject("ADODB.Stream")
  
  'Open a GIF file
  objStream.Type = adTypeBinary
  objStream.Open
  objStream.LoadFromFile "owc.gif"
  

  Response.ContentType = "image/gif"
  Response.BinaryWrite objStream.Read
 
  objStream.Close
  Set objStream = Nothing
%>


?
 
this is the error message that i got. line 7 is: objStream.Type = adTypeBinary


ADODB.Stream error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/gif.asp, line 7
 
Hi,
In case adTypeBinary is not recognized for some reason,
try:

objStream.Type = 1 ' adTypeBinary


instead

[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
i tried that. here's the error i'm getting now:
ADODB.Stream error '800a0bba'

File could not be opened.

/custom_apps/gif.asp, line 13

line 13 is: objStream.LoadFromFile "owc.gif
 
line 13 is: objStream.LoadFromFile "owc.gif"

is "owc.gif" in the same directory as "gif.asp" - if not, you need to specify the exact location of the file:

Code:
objStream.LoadFromFile = server.mappath("\mydir\subdir\owc.gif")

Foxbox - on another note - is there anyway to pass the file name as a paramater using session vars so more than one image can be shown on the same page using the same script?

I've tried this:

Code:
<% session("img") = "myImage.gif" %>
<img src="image.asp" />

<% session("img") = "anotherImage.gif" %>
<img src="image.asp" />

Code:
...
objStream.LoadFromFile server.mappath(session("img"))
...

^ but all that did was load and show the 2nd image twice...




--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
Put a Response.Flush
before
Code:
session("img") = "anotherImage.gif"
 
foxbox,
the code that you posted above and this line from vicvirk did the trick. very cooooooool!
objStream.LoadFromFile = server.mappath("\mydir\subdir\owc.gif")
you both deserve a star.
cheers.
 
another question that i have is:
can the file name in this line be a variable? if the file path/name was
file_name = "\mydir\subdir\owc.gif"
how would the following line look like?
objStream.LoadFromFile = server.mappath("\mydir\subdir\owc.gif")

thanks.
 
like always: there are many ways to Rome (its a Dutch saying).

vicvirk showed an example of "variable", by using a session variable.

another way is to call image.asp with a parameter, eg image.asp?id=1
and then (in image.asp) search a table for the folder/file name

if there is a very limited and fixed number of images you can do it with IF TEHN ELSE/ SELECT CASE block (eg when you have a Yes and No image)


 
thanks foxbox.
i did manage to put the image display in a file called image.asp
then when my page displays the image i have this:
<img src="image.asp">
this works ok.
in image.asp i have to have a variable file name in this line:
objStream.LoadFromFile = server.mappath("\puboffsearch\captcha\owc.gif")
i used session("img") and it didn't work
my code is:
page1.asp
Code:
<%for digit = 1 to 3 
session("img") = digit%>
<img src="image.asp" />
<%next%>
when i did this inside a loop 3, varying the digit, i get the last number repeated 3 times.
anything i'm doing wrong here?
thanks.








 
your loop is producing
session("img") = 1,
session("img") = 2 and
session("img") = 3

and you call image.asp 3 times. I presume you want to display 3 different gif's, so you must put
Response.Flush after the call to image.asp (to force the browser to spit out the image).

your session variable is an integer, so i hope for you that in image.asp the ".gif" is added, outerwise the script is searching for eg "\puboffsearch\captcha\1"







 
hi.
my page is this even without the loop, it doesn't work. it shows the last gif 2 times. i do add .gif to the digit when i go to image.asp
Code:
<%   
session("img") = "3" %>
 <img src="image.asp"></img>    
<%response.flush%>
     
<%session("img") = "4" %>
 <img src="image.asp"></img>    
<%response.flush%>
 
put Response.Buffer=true as 1st line.

and if that is not working, what error do you get?

 
hey, 3 stars got my attention! streaming a picture is indeed a nice trick. added to my code snippet collection. tnx foxbox
 
the code is showing the last .gif image twice. here's my code:
Code:
<% response.buffer = true 
session("img") = "3" %>
 <img src="image.asp"></img> 
<%response.flush%>

<% response.buffer = true 
session("img") = "5" %>
 <img src="image.asp"></img>
<%response.flush%>
i'm not getting an error. just the last picture shows up twice.
thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top