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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP question

  • 12-05-2006 11:31am
    #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: 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, 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: 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