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.
 
here's the code from image.asp
Code:
<% 
x = session("img")
dim images(10)
images(0) = "\puboffsearch\captcha\0.gif" 
images(1) = "\puboffsearch\captcha\1.gif" 
images(2) = "\puboffsearch\captcha\2.gif" 
images(3) = "\puboffsearch\captcha\3.gif" 
images(4) = "\puboffsearch\captcha\4.gif" 
images(5) = "\puboffsearch\captcha\5.gif" 
images(6) = "\puboffsearch\captcha\6.gif" 
images(7) = "\puboffsearch\captcha\7.gif" 
images(8) = "\puboffsearch\captcha\8.gif" 
images(9) = "\puboffsearch\captcha\9.gif" 

x = int(x)
file_name = images(x)
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open 
objStream.LoadFromFile = server.mappath(file_name) 
Response.ContentType = "image/gif"
Response.BinaryWrite objStream.Read 
objStream.Close
Set objStream = Nothing 
%>
 
mmmm that response.flush is not working. can't see why. we can spent another hour on this, or solve it another way, eg like this
Code:
<img src="image.asp?i=1">
<img src="image.asp?i=3">


image.asp
Code:
<%
dim i
i = request.QueryString("i")
if i = "" then i = 0

dim images(10)
images(0) = "\puboffsearch\captcha\0.gif"
images(1) = "\puboffsearch\captcha\1.gif"
images(2) = "\puboffsearch\captcha\2.gif"
images(3) = "\puboffsearch\captcha\3.gif"
images(4) = "\puboffsearch\captcha\4.gif"
images(5) = "\puboffsearch\captcha\5.gif"
images(6) = "\puboffsearch\captcha\6.gif"
images(7) = "\puboffsearch\captcha\7.gif"
images(8) = "\puboffsearch\captcha\8.gif"
images(9) = "\puboffsearch\captcha\9.gif" 

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile = server.mappath( images(i) )
Response.ContentType = "image/gif"
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
%>

 
thanks foxbox.
the whole idea is to hide the gif images from being seen in the source code. with querystring, the file name will be revealed. i tried another method. basically i created a folder with the name of the session that was a five-digit number (33452) then i copied
3.gif to file1.gif
3.gif to file2.gif
4.gif to file3.gif
5.gif to file4.gif
2.gif to file5.gif
then i used
<img src="<%response.wirte file1.gif%>" />
<img src="<%response.wirte file2.gif%>" />
<img src="<%response.wirte file3.gif%>" />........
So, the only thing that shows up in the source code is file1, file2, file3, file4 ..................
but windows requires some time for the copyfile method to settle before you can get the file and show it. so, my result has broken pictures. but, after a few seconds when i go to look at the directory, the files are there.
any idea how this new method can wait for the files to "settel"?
thanks.




 
Hi.
i have page1.asp that has this code:
Code:
  <%session("img") = "7.jpg"%>
        <td><img src="img.asp"></img></td>
<%response.flush%>  
  <%session("img") = "9.jpg" %>
        <td><img src="img.asp"></img></td>
<%response.flush%>
  <%session("img") = "8.jpg" %>
        <td><img src="img.asp"></img></td>  
<%response.flush%>
img.asp has this code:
Code:
image_file = session("img") 
  Dim objStream
  Set objStream = Server.CreateObject("ADODB.Stream") 
  'Open a GIF file
  objStream.Type = 1
  objStream.Open
  objStream.LoadFromFile server.mappath(image_file)
  Response.ContentType = "image/gif"
  Response.BinaryWrite objStream.Read
  objStream.Close
  Set objStream = Nothing
  session("img") = ""
  response.end
img.asp is just a binary write and gets session("img") as the fine name and works with a single image. but, when i do 3 images, the last images shows up 3 times. is there a way to get around this?
thanks.
 
HTML:
<img src="img.asp?id=1" />
<img src="img.asp?id=2" />

Code:
<%
 with response
	.CacheControl = "no-cache"
	.AddHeader "Pragma", "no-cache"
	.ContentType = "image/gif"
	.Buffer = true
end with

' get image id
img_id = request.querystring("id")

select case img_id
	case 1: img_name = "\mypath\myImg.gif"
	case 2: img_name = "\mypath\myNextImg.gif"
end select
  

dim objStream
set objStream = server.createObject("ADODB.Stream")
  
objStream.type = 1
objStream.open

objStream.loadFromFile server.mapPath(img_name)
   
response.binaryWrite objStream.read
  
objStream.close
set objStream = nothing
%>


--------

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


--------
 
vicvirk,
thanks much. this looks promising. i tried this code and it gave me a broken pic side by side, which is something i never had seen before using binarywrite. at least it' showing the two broken images side by side. the gif files are at:
inetpub/ directory.
how would it be referenced in this line:
objStream.loadFromFile server.mapPath(img_name)
in img.asp?
thanks much
 
RESOLVED.
IT WORKED.
thanks vicvirk. i displayed both images side by side. this is great. i looked all over the net to find code that made displaying images side by side possible using binarywrite - i couldn't find any. you're great. you deserve a few stars.
thanks so much.
 
displaying multiple gif's is going ok now.
the only problem right now is that the id is showing up on the html source code. i wonder if session variable can do the trick?
<img src="img.asp?id=1" />
thanks.
 
?! This solution is exactly what i proposed on 11 Mar 10 9:19

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)

This gets the work done, although not very nice programming:

page1.asp
Code:
<% session("img1") = 1 %>
<img src="image.asp" >
<% session("img2") = 2 %>
<img src="image2.asp" >

image.asp
Code:
<%
file_name = session("img1") & ".gif"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile = server.mappath(file_name)
Response.ContentType = "image/gif"
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
%>


image2.asp
Code:
<%
file_name = session("img2") & ".gif"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile = server.mappath(file_name)
Response.ContentType = "image/gif"
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
%>
 
Code:
displaying multiple gif's is going ok now.
the only problem right now is that the id is showing up on the html source code. i wonder if session variable can do the trick?
<img src="img.asp?id=1" />
thanks.

I don't quite understand the exact reasoning behind what you are trying to do here...why is it SO important that you hide any information about the file from the view source?

As Foxbox mentioned, the session variable method is exactly what he recommended earlier, if that doesn't work, maybe enlighten us as to why you want to be so secretive with the images and maybe we can come up with a different method for you.




--------

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


--------
 
vicvirk,
thanks for the reply. here's the situation: i have looked around to find a captcha program that will fit our particular application. most of them do not suit what we are doing. they just sit on one screen and display "correct" or "incorrect". having said that, main_page.asp will give control to page1.asp which display the 5-6 digit number using
<img src="img.asp?id=1" />. page1.asp check the input by the user against the captcha random number and if correct, it links to page2.asp. random captcha number is being pased to page2.asp via session("rand").
now, if we put src="img.asp?id=1" /> then the source code will reveal the digits being displayed. displaying of the digits works perfectly and the digits are displayed side by side with no problem. the only problem is revelation of the random captcha number. i tried making session variable a digit and invoke img.asp, but, it displayed the last digit 5 times. i hope i am making my project clear.
thanks much
 
what are you using the captcha for? I find it hard to believe that you have come up with something that isn't already accounted for....

Captcha's don't just sit on the screen, their values are stored in session variables (at least the ones I've used) and upon submit of the form, the page processing the request gets the value entered by the user and compares it against the session var...if it is correct, the program continues...






--------

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


--------
 
vicvirk,
quote:
if it is correct, the program continues...
end quote.
continues where? you mean processes your data? i have not seen a captcha that will link to a new page after entering the captcha code. maybe you can put me in the right direction. most of the ones i have seen, just display "correct" or "incorrect" after you click the submit button. if you know of any, please let me know. the application we have is:
main_page.asp ---> page1.asp ---> page2.asp
we don't want a bot/spam to run page1.asp or page2.asp using link parameters.
thanks.
 



^ the way they ALL work is as follows (in one shape or another)

HTML:
<form action="mypage.asp" method="post">
<input type="text" id="tbx" name="tbx" />
<input type="text" id="captcha" name="captcha" value="" />
<input type="submit" />
</form>

Code:
<%
' what to name this var will be defined in the documentation
captcha_entered = request.form("captcha")
<!--#include file="location\captcha_verification_file.asp" -->
' the above will return a variable called something like "captcha_verified"

if not captcha_verified then
 ' error on captcha value entered
 response.write "INVALID SECURITY CODE!"
response.end
else
 tbx = request.form("tbx")
 'continue processing
end if
%>


--------

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


--------
 
thanks vicvirk.
is this include file:
<!--#include file="location\captcha_verification_file.asp" -->
related to any of the links that you posted above? i could not find it in any of those links after downloading them. can you please post which captcha this inlude file belongs to?
thanks.
 
thanks vicvirk.
is this include file:
<!--#include file="location\captcha_verification_file.asp" -->
related to any of the links that you posted above? i could not find it in any of those links after downloading them. can you please post which captcha this inlude file belongs to?
thanks.

It will be in the documentation of the one you downloaded - mine was just an example...

Basically, you're added code written by someone else to your program. Instead of embedding the code into your site, you just use a SSI to add the contents to which ever pages you want.




--------

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


--------
 
thanks vicvirk.
i get the picture now. i got it to work. i was under the impression that i have to put this captcha page between my main_page.asp and page1.asp, i.e.
main_page.asp ---> captcha ---> page1.asp
but, now after reading your last post, i'm clear now. i have to put this "demo" captcha page code in front of my page1.asp
my page1.asp will check the answer. if not correct, it will stop with response.end, otherwise, it will continue with all the data and images in my page1.asp.
thanks so much. i got it to work perfectly.
:)
cheers
 
i have to put this "demo" captcha page code in front of my page1.asp
i meant to say:
i have to put this "demo" captcha page code INSIDE my page1.asp at the very beginning.
thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top