If we want to add on to a file we need to open it up in append mode.

$myFile = "testFile.txt";
$fh = fopen($myFile, 'a');

Then we use fwrite() to write to the file. It would begin writing data at the end of the file.

$myFile = "testFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Hello\n";
fwrite($fh, $stringData);
$stringData = "We are vn4000\n";
fwrite($fh, $stringData);
fclose($fh);

Related Posts by Categories