PHP Problem

  Nelmon2k 20:39 13 May 05

I'm attempting to create my own read and write script to stop me having to directly change the code on my site using FTP. To do this I'm using the following code.

$myfile = fopen ("mytext.txt","r+");
flock ($myfile, LOCK_EX);
fwrite ($myfile, "Random Test Again");
flock ($myfile, LOCK_UN);
fclose ($myfile);

However when I run this it erases the first part of the file similar to what is experienced when using the overwrite command on word. Is there a way to stop this???

  Nelmon2k 21:03 13 May 05

sorted... I've managed to sort it by using the following method if anyone is intrested.

$file = "mytext.txt";
$contents = file_get_contents($file);
$contents = "Add this text to the file".$contents;

$fp = fopen($file,"w");

  harristweed 10:52 14 May 05

change $myfile = fopen ("mytext.txt","r+");

to $myfile = fopen (mytext.txt,'a');

This will (should) open the file in 'append' mode, therefore add to, rather than overrite, i've NOT tested it.

  harristweed 10:54 14 May 05

to $myfile = fwrite (mytext.txt,'a');

  Nelmon2k 11:40 19 May 05

Thanks but the aim of it was to create a script I could use to create a latest news system so it had to be at the top of the script

This thread is now locked and can not be replied to.

Surface Pro (2017) vs Surface Pro 4

Where HTML5 is headed next

MacBook Pro v Surface Pro 5