Appending to a File


You want to write content to the end of a file.


Use the File::append() method.

$bytesWritten = File::append($filename, $content);
if ($bytesWritten === false)
    die("Couldn't write to the file.");

This will add the content to the end of existing files. If the file doesn't exist then the entire contents will be $content.


Watch the return value.

If there's a problem writing to the file false is returned.

comments powered by Disqus