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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Dec 2002
    Location
    Israel
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Download file instead of navigate to URL

    Is it possible to create link that will start file download ("Save target as...") instead of navigate to URL?

    Thanks in advance for any suggestions.

  • #2
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    i think it's possible in IE, but not cross browser. the best way to make it happen cross browser, is to zip it, as most browsers are set to automatically download zip files.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #3
    New to the CF scene
    Join Date
    Dec 2002
    Location
    Israel
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks.

    The best solutions I come with are:
    to use ExecWB of IE or to zip target file.

    Still may be there is some other trick out there?

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There is a method in IE called execCommand; it goes something like

    document.execCommand("saveas","filename");

    MSDN will have more ....

    ... but, it is IE only. The way to acheive this is server side. In PHP you make this file called "download.php":

    PHP Code:
    <?

    $saveName 
    stripslashes($HTTP_GET_VARS["name"]);
    $savePath stripslashes($HTTP_GET_VARS["path"]);

    header ("Content-Type: application/octet-stream");
    header ("Content-Disposition: attachment; filename=$saveName");
    header ("Content-Transfer-Encoding: binary");
    readfile($savePath);

    ?>
    And then you call it with a link like this:

    Code:
    <a href="/download.php/?path=music/hifi/songname.mp3&name=songname.mp3">

  • #5
    New to the CF scene
    Join Date
    Dec 2002
    Location
    Israel
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, brothercake, it work like magic.

    Here mine interpretation in ASP for anyone interesting:

    <%
    Response.Write MapPath(Request.QueryString("Path").Item)
    Response.AddHeader "CONTENT-TYPE", "application/octet-stream"
    Response.AddHeader "CONTENT-DISPOSITION", "attachment; filename=" & Request.QueryString("Name").Item
    Response.AddHeader "CONTENT-TRANSFER_ENCODING", "binary"
    dim fso, f, ts
    set fso = CeateObject("Scripting.FileSystemObject")
    Set f = fso.GetFile(MapPath(Request.QueryString("Path").Item))
    Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
    Response.Write ts.ReadAll
    %>

    You can call it with:
    <a href="download.asp?Path=test.txt&Name=saveas.txt">Click here to download</a>

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cool

  • #7
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    i'm gonna move this to the General Web Building forum. is this maybe one that we want to put in the archives?
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would say yes, john - this question pops up so much etc. and this thread is a good answer

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #9
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That covers the IE side of it. For Mozilla/Netscape, you shift-click the link to Save As...


  •  

    Posting Permissions

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