I'm trying to get a form to ADD new text to the beginning of an existing file.
If I use
@fopen($filename, "r+")
it overwrites what's at the beginning of the file as opposed to inserting it into the beginning.
I played around with trying to fopen "r" the file then w+ writing the new info followed by the old info, but I don't know how to "cache" a file in order to write its contents.
Here's what I tried, and of course it's not working, but if someone can suss from this what I'm trying to do and lemme know what PHP function I'm needing, I'd be more than happy to take it to php.net and learn about it. =)
Thanks!
(snippet of code...)
$input = "<option value=\"" . $date2 . "\">" . $title . "</option>";
$oldfilename = "curlist";
$oldfile = @fopen($oldfilename, "r") or die("Couldn't open file.");
$olddata = $oldfile;
$newfilename = "curlist";
$myfile = @fopen($newfilename, "w+") or die("Couldn't open file.");
@fwrite($myfile, $input) or die("Couldn't write new data to file.");
fclose($myfile);
$myfile2 = @fopen($newfilename, "a+") or die("Couldn't open file.");
@fwrite($myfile2, $olddata) or die("Couldn't write old data to file.");
fclose($myfile2);
fclose($oldfile);