File_put_content
Started on the old forum in January 2013 · view the original in the archive · old links redirect here
not with that code as its full of syntax errors.
but this would work
<?php
$file = 'data/data.txt';
$string = 'A Testing Message Inside A Txt File.'; //Can Be Blank also.
file_put_contents($file, $string);
?>
//
//
//
to append to file this way you would do
<?php
$file = 'data/data.txt';
$string = 'A Testing Message Inside A Txt File.'; //Can Be Blank also.
file_put_contents($file, $string, FILE_APPEND | LOCK_EX); // LOCK_EX would stop anyone else writing to the file at the same time.
?>
//
//
//
although im not sure it actually sets the file permission for you. so you could add to end of that.
chmod($file, 0777);
//
//
//
file_put_contents function context was only added to PHP at version 5.0.0. This function is just a PHP Wrapper and is actually identical to calling fopen(), fwrite() and fclose() successively to write data to a file. The ability to lock a file while it is being used with the LOCK_EX flag was added in PHP 5.0.1.
Use file_put_contents($file, $data, FILE_APPEND); to append date to the end of a file.
Regards, Rob