Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP question

  • 12-05-2006 12:31PM
    #1
    Registered Users, Registered Users 2 Posts: 2,621 ✭✭✭


    Hi guys,
    I have a script that creates a basic text file and I want to know how to make it available for download, within the script, if that makes sense?

    Kind of like when you click on a link and off it goes and does its thing and returns download box.


Comments

  • Registered Users, Registered Users 2 Posts: 684 ✭✭✭Gosh


    Assuming your download file is called "downloadfile.txt" then at the point on the page where you want to place thew download link:
    echo '<a href="downloadfile.txt">Download File Now</a>';
    


  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    http://ie2.php.net/readfile


    read through the comments


  • Registered Users, Registered Users 2 Posts: 3,514 ✭✭✭Rollo Tamasi


    Gosh, that would only open up the txt file in the browser


  • Closed Accounts Posts: 169 ✭✭akari no ryu


    Try this:
    <?php
    header("Content-type: application/force-download");
    $pathToFile="your/path/goes/here.txt";
    $file=readfile($pathToFile);
    echo $file;
    ?>
    


  • Closed Accounts Posts: 169 ✭✭akari no ryu


    Failing that, you could try this
    <?php
    $filename="yourFile.txt"l
    $path="/your/path/goes/here/";
    header("Content-Disposition: attachment; filename=$filename");
    echo readfile("$path/$file");
    ?>
    


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 684 ✭✭✭Gosh


    Gosh, that would only open up the txt file in the browser

    True - should have been
    echo '<a href="downloadfile.txt">Right-Click and Save Link/Target As to Download File</a>';
    


Advertisement