+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: how to create a link that download...

  1. #1
    batman1's Avatar
    batman1 is offline x10Hosting Member batman1 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Jamaica
    Posts
    92

    how to create a link that download...

    Hey I want ot download a text file but with the code below it opens the text file in a new window.

    Code:
    <a href="textfile.txt">download here</a>
    Whats the code to make that when i click the link the file can be downloaded onto my computer.

    Thanks
    Last edited by batman1; 06-12-2009 at 10:49 PM.

  2. #2
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: how to create a link that download...

    That -is- the code to download it to pc - your systems browser is set to a different action by default however, so it's not having the intended effect.

    In short the code is right, the browser's doing it wrong - not really a way to code it so it forces it to download that I know of, other than right-click, save-target-as


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  3. #3
    mattura's Avatar
    mattura is offline x10 Elder mattura is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    563

    Re: how to create a link that download...

    Once it opens in a new window, click file...save as. You have already downloaded it! What browser are you using?
    ----
    Life is a game. The conception is terrible but the graphics are amazing!
    matt.elementfx.com

  4. #4
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: how to create a link that download...

    I believe many browsers can view .txt files. So, by default they open them, similar to a .html file. Maybe this will help: http://stackoverflow.com/questions/186867?sort=votes
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  5. #5
    sourfacedcyclop's Avatar
    sourfacedcyclop is offline x10 Sophmore sourfacedcyclop is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    221

    Re: how to create a link that download...

    If you add it to a zip folder and upload it to the server and then link to the folder it should download.
    "Sanity is nothing but our interpretation of reality"

    http://tswebvisions.com - Portfolio

  6. #6
    zen-r's Avatar
    zen-r is offline Lord Of The Keys zen-r is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Location,Location. Nothing else matters ....apparently.
    Posts
    1,937

    Re: how to create a link that download...

    Quote Originally Posted by sourfacedcyclop View Post
    If you add it to a zip folder and upload it to the server and then link to the folder it should download.
    I was about to say something similar myself!

    Uploading it as a zip file will also make it smaller & save space / download time (though of course, it adds some hassle for the user having to unzip it again).
    For great installation & servicing of Audio Visual systems & equipment
    inc. LCD & Plasma Screens, Loudspeakers, Projectors, Aerials & Satellite Dishes, Lighting effects & controllers, Hifi, Amplifiers, Surround Sound, Home Cinema & Video etc
    -: based around Plymouth, Devon, or anywhere in the southwest of the UK, visit :-

  7. #7
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: how to create a link that download...

    I guess it depends on the size of the text file. If you're zipping a 10kb text file (like most of them are ) you really gain nothing by zipping it. Unless you anticipate your users are on 14.4kbs dialup. The .zip extension just guarantees that your browser won't try to open it. But, you can do the same thing with the link I posted above and use any file extension ;)
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  8. #8
    daman371 is offline x10 Sophmore daman371 is an unknown quantity at this point
    Join Date
    Nov 2006
    Location
    Louisiana
    Posts
    130

    Re: how to create a link that download...

    You have send the header to download the file. It involves a little PHP or another web language. PHP is the one I know though. Put this code in a file called text.php or something. Of course you have to change the Content-Length parameter.

    Code:
    <?php
    header('Content-Type: text/plain');
    header('Content-Length: 1234');
    header('Content-Disposition: attachment;filename="textfile.txt"');
    $fp=fopen('textfile.txt','r');
    fpassthru($fp);
    fclose($fp);
    ?>

  9. #9
    batman1's Avatar
    batman1 is offline x10Hosting Member batman1 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Jamaica
    Posts
    92

    Re: how to create a link that download...

    Quote Originally Posted by daman371 View Post
    You have send the header to download the file. It involves a little PHP or another web language. PHP is the one I know though. Put this code in a file called text.php or something. Of course you have to change the Content-Length parameter.

    Code:
    <?php
    header('Content-Type: text/plain');
    header('Content-Length: 1234');
    header('Content-Disposition: attachment;filename="textfile.txt"');
    $fp=fopen('textfile.txt','r');
    fpassthru($fp);
    fclose($fp);
    ?>
    thanks for your reply I will try this.

  10. #10
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: how to create a link that download...

    I understand the text file problem, but why then do certain images enforce a download rather that just viewing them? That can get really irritating when image searching.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Link Exchange with me
    By simpleboy in forum Ads & Offers
    Replies: 3
    Last Post: 11-14-2008, 08:18 PM
  2. Free One Way Link for your website.
    By gogulf in forum Link Exchange
    Replies: 4
    Last Post: 11-08-2008, 03:43 PM
  3. Topsite List
    By vmadmin in forum Advertising
    Replies: 3
    Last Post: 04-07-2008, 07:18 AM
  4. Link Exchange
    By Conor in forum Scripts & 3rd Party Apps
    Replies: 117
    Last Post: 12-09-2007, 12:20 PM
  5. How Do I Create A Link
    By OFERX10 in forum Introductions
    Replies: 5
    Last Post: 10-25-2007, 10:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers