Loans - Personal Loans - Mortgages - Buy Anything On eBay - Unblock Myspace

PDA

View Full Version : Add date


Adbie.for.ever
Apr 26th 2008, 7:43 am
Hi,

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

Thankx

CPURules
Apr 26th 2008, 10:20 am
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);
?>