PHP Problem

  Nelmon2k 20:39 13 May 2005
Locked

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 2005

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");
fwrite($fp,$contents);
fclose($fp);

  harristweed 10:52 14 May 2005

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 2005

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

  Nelmon2k 11:40 19 May 2005

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.

Elsewhere on IDG sites

Galaxy Note 8 vs iPhone X

Aardman's new YouTube channel to share the work of independent animators

iPhone X vs Samsung Galaxy Note 8

Les meilleurs navigateurs internet 2017