Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP question

Options
  • 12-05-2006 12:31pm
    #1
    Registered Users 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 Posts: 683 ✭✭✭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 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 Posts: 683 ✭✭✭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