Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-07-2011, 01:41 PM   PM User | #1
sda
New to the CF scene

 
Join Date: Mar 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sda is an unknown quantity at this point
Prompt user for download - Please help!

Hi

I have zero experience using ASP and I'm really stuck.

A client wanted an image gallery making with a load of thumbnails and when the visitor clicks on the thumbnail it prompts for a download.

I have made the gallery with all the thumbnails and put the thumbnail inside an <a> when the visitor clicks on the link it directs to download.asp and passes through the image name as a variable called image.

i.e.

<a href="download.asp?images=file-name.jpg><img src="images/thumbnails/file-name.jpg" alt="" /></a>

So far I have managed to get the script to prompt for a download but the image was empty when i downloaded it so i tried to use Server.MapPath and now it doesn't work at all.

Here is download.asp

<%
'Set variable image and get image name though the url
dim image
image= Request.QueryString("image")

Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename="&image)

Response.ContentType = "image/jpeg"
Response.TransmitFile( Server.MapPath("~/images/hi/"&image))
Response.End()

%>

Please could someone point me in the right direction.

Thanks a lot

Harrison
sda is offline   Reply With Quote
Old 03-07-2011, 07:45 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,578
Thanks: 62
Thanked 4,062 Times in 4,031 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Where did you come up with Response.TransmitFile ????

No such thing.

Look here:
http://msdn.microsoft.com/en-us/library/ms525405

Also, you can't use ~ in a path with Server.MapPath and ASP. That's an ASP.NET-ONLY convention.

It's been quite some time since I have done this, but it should be *something* like this:
Code:
<%
' make sure there are *NO* characters in the file prior to the < of the above line!

name = Trim(Request("image"))

Set strm = Server.CreateObject("ADODB.Stream")
strm.Type = 1 ' binary
strm.LoadFromFile( Server.MapPath( "/images/hi/" & name ) )

Response.AddHeader("content-disposition", "attachment;filename="&name)
Response.ContentType = "image/jpeg"

Response.BinaryWrite strm.Read

Response.End
' stuff after here does not matter as response.end means "end now"
%>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Tags
download, prompt

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:59 AM.


Advertisement
Log in to turn off these ads.