Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Thanked 0 Times in 0 Posts

    Prompt user for download - Please help!


    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.


    <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.AddHeader("content-disposition", "attachment;filename="&image)

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


    Please could someone point me in the right direction.

    Thanks a lot


  2. #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,947 Times in 4,908 Posts
    Where did you come up with Response.TransmitFile ????

    No such thing.

    Look here:

    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:
    ' 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
    ' stuff after here does not matter as response.end means "end now"
    Be yourself. No one else is as qualified.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts