Answers for "open file write append php"

PHP
7

php append to file

// LOCK_EX will prevent anyone else writing to the file at the same time
// PHP_EOL will add linebreak after each line
$txt = "data-to-add";
$myfile = file_put_contents('logs.txt', $txt.PHP_EOL , FILE_APPEND | LOCK_EX);

// Second option is this
$myfile = fopen("logs.txt", "a") or die("Unable to open file!");
$txt = "user id date";
fwrite($myfile, "\n". $txt);
fclose($myfile);
Posted by: Guest on May-13-2020
1

append file in php

$fptr = fopen('myfile2.txt','a');
fwrite($fptr,"hii.. this is appending inside file\n")
fclose($fptr);
Posted by: Guest on October-12-2021

Browse Popular Code Answers by Language