PHP – File Append

by Hiroshi on June 23, 2008

in File, File Manipulation

File append means to add on to the existing data, then you need to open the file in append mode.

<?php
$myFile = "testFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "New data 1\n";
fwrite($fh, $stringData);
$stringData = "New data 2\n";
fwrite($fh, $stringData);
fclose($fh);
?>

In this way the target file will be opened and new data will be inserted after old data in the file.

Related Posts

Previous post:

Next post: