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

    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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    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.


  •  

    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
    •