Can anyone help out with reading from a file and saving the current contents? What I have is, a script that writes data
to a file, but everytime u click a button, it overwrites the data.
How can I with my current code, save the current contents
above the old contents, according to the date in my file?
Does that make sense?
So for example my file would look like this:
July 21st 2004
What a great day it is
Woohooo!
July 20th 2004
Hello Word
How are you
Here is my script code
<?
if(isset($_POST['check'])) {
//itterate through check boxes to check which are checked
foreach($_POST['check'] as $key => $value) {
$today = date("F-d-Y");
$filename = $today.".ticker_archive.html";
$path = "C:/Inetpub/wwwroot/bna-intranet/ticker_archive/";
$somecontent = "<table><tr><td><font face=\"$fontstyle\" color=\"$fontcolor\" size=\"$fontsize\">".$value."</font></tr></tr></table><br />";
// Let's make sure the file exists and is writable first.
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "<p align='left'><b>Successfully</b>, wrote (<font face=\"$fontstyle\" color=\"$fontcolor\">". strip_tags($somecontent) ."</font>) to file<br />";
fclose($handle);
}
echo "<br /><br /><br /><br />";
// Copies the file over to another directory
if (!copy($filename, $path.$filename)) {
echo "Failed to copy $filename...<br />\n";
} else {
echo "Your file <u>$filename</u> has been copied too $path<br /><br />\n"; }
// After the file has been copied, it gets deleted
if (file_exists($filename))
{
unlink($filename);
}else{
echo ("$filename could not be found!");
}
// foreach loop end bracket
} else {
echo "<font size='2'>I'm Sorry, No boxes are checked!</font><br/>\n";
}
?>