Page 1 of 1

fopen problems. Can't write to first line with simple code.

Posted: Fri Nov 01, 2002 8:24 pm
by seg
I have been using a long script to overcome a problem I have been having. Here is the long version.

Code: Select all

// get old
$fp = fopen("$filename","r");
$old = fread($fp, filesize ($filename));
fclose($fp);
// kill file, write new then old
$fp = fopen($filename,"w");
fputs($fp,"$new $old");
fclose($fp);
This will save all the current data, and write the new info to the first line, and everything under it.

Seems the simple way to do this would be

Code: Select all

$fp = fopen($filename, "r+");
fputs($fp, $new);
fclose($fp);
But that does not work. PHP.net says the "r+" tag keeps the data, and puts the fp at the beginning of the file. In practice, though, it will post the new info once, then from that point on, it will post only part of the $new variable, or cut existing data. I've got no friggin idea what is going on with this. Can someone shed some light? php.net says this should work.
thanks
-seg

Posted: Sat Nov 02, 2002 9:34 am
by seg
I just re-read my post, wow, I was dead tired last night. I'm going to do some actual testing and figure this out today. Reading my post now I not surprised no one responded. heh. If I still can't figure this crap out, hopefully I'll be able to compile a direct question with a more accurate description of the problem.