• 13Nov

    Here I demonstrate the ability for PHP to save files, with both the PHP 5 and PHP 4 method. Using file_put_contents() I can save files, or I can use fopen(), fwrite(), and fclose() to save a file. Naturally it is easier to use the single function available in the latest PHP build. If you want to refer back to the previous tutorial where I demonstrated loading files, you can see how these two pretty much go together.
    You need flash to play this tutorial.
    This tutorial goes over the following goals:
    Save a file
    Overwrite a file
    The differences between the PHP 5 method and the PHP 4 method
    You can find this tutorial video on youtube here.

    Here are the sources used in this tutorial:
    tut029.php
    <?php
    //PHP Tutorial 029 Saving Files 
    //PHP 5 method and earlier.
    $data = "my socks rock like the sky";
    $filename = "test2.txt";
    //in PHP 5 you can use the below line to save a file
    file_put_contents($filename, $data);
    //in PHP 4 you can use the below to save a file
    $fh = fopen($filename, "w");
    fwrite($fh, $data);
    fclose($fh);
    ?>

    Here are all the php functions used in this tutorial:

    Posted by Kloplop321 @ 5:57 am

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.