Add date

Discussion in 'PHP' started by Adbie.for.ever, Apr 26, 2008.

  1. #1
    Hi,

    How can I add the date to this file (day / month / year)?
    $fc = fopen($dirname."Testname - $filename", "wb");

    Thankx
     
    Adbie.for.ever, Apr 26, 2008 IP
  2. CPURules

    CPURules Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This assumes that by Day/Month/Year, you mean 26/04/2008.

    $dirname needs to be set to the DIR in relation to where this script is running
    $filename is (obviously) the filename to append the date to.
    
    <?php
    $dirname = "testdir";
    $filename = "testfile.txt";
    
    $file = fopen($dirname.$filename, "a");
    
    if(!file_exists($dirname.$filename)) {
    die("<font color=\"red\"><b>Error:</b> Could not open file: " . $dirname.$filename . "</font>");
    }
    
    $write = fwrite($file, date("d/m/Y"));
    if(!$write) {
    die("<font color=\"red\"><b>Error:</b> Could not write to file: " . $dirname.$filename . "</font>");
    }
    
    fclose($file);
    ?>
    
    PHP:
     
    CPURules, Apr 26, 2008 IP