Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 22nd, 2004, 03:20 PM
dkb dkb is offline
Authorized User
 
Join Date: Oct 2003
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default Returning an image from an ASP page

Could anyone advise me how to return an image from an ASP page?

Say for example you would like to provide an image tag with a source that links to a page:-

<img src="http://www.aServer.anAspPAge.asp?name="x.jpg">

I know it can be done in asp.net, can it be done in ASP.

Thanks.

 
Old September 23rd, 2004, 03:18 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

If you want to read the image from your file system & write it from asp, you can do this
Code:
Response.ContentType = "image/jpg" ' "image/gif" "img/png"
Dim stream
Set stream = Server.CreateObject("ADODB.Stream")
Call stream.Open()
stream.Type = adTypeBinary
Call stream.LoadFromFile("[path to file here]")
Call Response.BinaryWrite(stream.Read())
Set stream = Nothing
n.b. you will need to reference the ado constants or substitute 1 for adTypeBinary fo this to work.

HTH,

Chris

 
Old September 23rd, 2004, 03:41 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You may also want to add:
Code:
Response.Flush
Response.End
to the end of the code as I have known it hang sometimes on large images.

--

Joe
 
Old September 23rd, 2004, 04:46 AM
dkb dkb is offline
Authorized User
 
Join Date: Oct 2003
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Chris,Joe,

Thanks very much, will have a go.



 
Old February 21st, 2008, 01:20 AM
Registered User
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not sure if this is helpful but I think you can simplify the code by using server.execute, i.e.

Code:
Response.ContentType = "image/GIF"
server.Execute("/images/shared/t.gif")
Does anyone have any comment on this alternative technique? Seems to work for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning current page number Larry Landis Word VBA 1 January 26th, 2007 09:23 AM
Returning Stored Procedure Results from ASP page JennaAckerson Classic ASP Basics 0 December 23rd, 2005 11:44 AM
make an image rollover that calls an asp page gavmc Classic ASP Basics 0 December 15th, 2005 12:13 PM
returning XML from ASP page amrit_82 Classic ASP Professional 4 July 6th, 2004 05:37 PM
Counting Users returning to a page they filled out bicho Classic ASP Basics 1 July 6th, 2003 03:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.