SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    download.asp file - how does this work

    hello,

    i see on some webpages where they have a link to download something and use the download.asp?code=some argument. question, how does this work and what do you need to do to get it to work? i know that someone can right click on an image and can download it that way. i would like to have it a little more personal to where they click on an image (ie: i have a spinning diskette image) where someone can click on it (the name of the image is passed so you can download the correct image, ie: image01.jpg or image02.gif or whatever, the image filename may change with each image.), and i would like it to open the SaveAs dialog box so the user can download the image. just as when you click on a software link and the Save dialog box comes up and allows you to click save to save the file. i know it can be done, just dont know how to make it work.

    go here and you can see what i am trying to do:
    http://johnandcheryl.0catch.com/love...9&11&20002009/

    in the link below the "imagename.ext" need to be a variable.

    this is the line of code that i am trying to get to work:
    <a href="http://johnandcheryl.0catch.com/loveis/download.asp?code=imagename.ext" onmouseover="doTooltip(event,2)" onmouseout="hideTip();"><script language="JavaScript1.2">document.write('<img src="graphics/bullets/computer/floppy_disk_rotation_med.gif" border=0 width=32 heigth=15 alt="Right Click on Panel, then select "Save Picture/Image As" to Save this Panel">');</script></a>

    however on the site you are viewing this is commented out cause i cant get it to work, so when you place the mouse cursor over the rotating disk it gives instructions on how do save the image.

    thanks for your help,
    John....

  2. #2
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To force the Save As... dialog, your ASP script must set the HTTP Content-Disposition header appropriately.

    http://support.microsoft.com/kb/260519

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is the download.asp file:

    <html>
    <head>
    </head>

    <body>

    <%
    sFile = request.querystring("file")
    sPath = "johnandcheryl.0catch.com/loveis/" & sFile
    sName = request.querystring("name")
    ContentType = "application/x-msdownload"
    Response.Buffer = True
    Const adTypeBinary = 1
    Response.Clear
    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = adTypeBinary
    objStream.LoadFromFile sPath
    ContentType = "application/octet-stream"
    Response.AddHeader "Content-Disposition", "attachment; filename=""" & sName & """"
    Response.Charset = "UTF-8"
    Response.ContentType = ContentType
    Response.BinaryWrite objStream.Read
    Response.Flush
    objStream.Close
    Set objStream = Nothing
    %>

    </body>
    </html>
    sPath = "domaindir" & sFile - domaindir is my root domain directory.

    below is the code i use to call this file:
    <script language="JavaScript1.2">document.write('<a href="domaindir/download.asp?file="' + photoname + "&name=file%20" + panelname + ".jpg" + '" onmouseover="doTooltip(event,2)" onmouseout="hideTip();">');document.write('<img src="graphics/bullets/computer/floppy_disk_rotation_med.gif" border=0 width=32 heigth=15 alt=""></a>');</script>

    when i tried this it loaded the download.asp file into the browser. no file download dialog box came up.... what am i missing for this to work....

    thanks,
    john....

  4. #4
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you saying it displays your ASP code in the browser? That would be a type handler issue with the server.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by World Wide Weird View Post
    Are you saying it displays your ASP code in the browser? That would be a type handler issue with the server.
    yes it displays the ASP code into the browser..... do i need the <html>,<head>,<body> statements or do i leave them out and just have the ASP code....

    how else can this work?

  6. #6
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jbetts1967 View Post
    yes it displays the ASP code into the browser..... do i need the <html>,<head>,<body> statements or do i leave them out and just have the ASP code....

    how else can this work?
    The problem is in your server configuration, not in your HTML. The server should always parse the ASP script and print out HTML. It should never print out the source code of a server script. I presume you're using IIS, not Apache. I'm an Apache guy, so I'll have to refer you to the forums that handle IIS issues for help with this.


Bookmarks

Posting Permissions

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