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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Force download dialogue box

    Hi guys

    Newbie here, so be gentle! I'm looking at having some files uploaded to my site which, when someone clicks on them, they are prompted to download rather than have them open in the browser (due to size and reason for having them there).

    I've downloaded the following script from a website but, not knowing anything really about VB or ASP scripting, amd really stuck on how to get this to work.

    Basically, I have a hyperlink which, when clicked, should prompt the user to download a file. The file, for arguments sake, will be Doc1.pdf. The filedownloader.asp file will be held in the cgi-bin folder (I'm assuming that's the right place for an ASP file?).

    The site I got this from instructed me to use the following link:

    http://mydomain/filedownloader.asp?filename=Doc1.pdf

    Altering this to:

    http://mydomain/cgi-bin/filedownloader.asp?filename=Doc1.pdf

    to put the ASP into the CGI-BIN folder, the hyperlink works, the dialogue box comes up but instead of downloading the Doc1.pdf file it tries to download the fileuploader.asp file instead!

    Can anyone please show me what bits of this coding I need to replace with what file references in order to get this to work? Trying to read through some of the other forums it is very difficult to follow and it's driving me mad!! Therefore some plain English would be great!

    Thanks in advance!

    Lee

    <%
    '=======================
    'Define the names of your functions
    '=======================
    Dim Stream
    Dim Contents
    Dim FileName
    Dim FileExt
    Const adTypeBinary = 1
    '=======================
    'Get the actual file name from the URL that is passed to the browser
    '=======================
    FileName = request.querystring("filename") 'Get the name from the URL
    '=======================
    'GIVE AN ERROR MESSAGE IF THE URL IS EMPTY
    '=======================
    if FileName = "" Then
    response.write "Filename Not specified."
    response.end
    end if
    '=======================
    'prevent access to certain files
    '=======================
    FileExt = Mid(FileName, InStrRev(FileName, ".") + 1)
    select case UCase(FileExt)
    Case "ASP", "ASA", "ASPX", "ASAX", "MDB"
    response.write "You cannot access these file types."
    response.end
    end select
    '=======================
    'Start the download process if all is good
    '=======================
    response.clear
    response.contentType = "application/octet-stream"
    response.addheader "content-disposition", "attachment; filename=" & FileName
    set stream = server.CreateObject("ADODB.Stream")
    stream.type = adTypeBinary
    stream.open
    stream.LoadFromFile Server.MapPath("/files") & FileName
    while not stream.EOS
    response.BinaryWrite Stream.Read(1024 * 64)
    wend
    stream.Close
    Set stream = Nothing
    response.Flush
    response.End
    %>

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    .asp files shouldn't be in the CGI-BIN folder.
    There are probably different permissions set for that folder.


    Upload the script the webroot or a subfolder.
    Where are your files stored?
    What is the path?

  • #3
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    All of the relevant files are in the root folder. I think my big problem is that I don't know how to configure the asp coding. If someone can help I'd be most grateful.


  •  

    Posting Permissions

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