1

Trying to append file with either:

file_put_contents($filename, "\r\n" . $barcode_number.PHP_EOL, FILE_APPEND);

or

$myfile = fopen($filename, 'a+');

neither appending my file. Both are over writing old information
Things I have tried are in code comments

    $myfile = fopen($filename, 'a+') or die("unable to open file" . $filename);

    $barcode_number = $_POST['SBN'];
    //$newLine = PHP_EOL; 
    //echo  $temp.$barcode_number; die();

    fwrite($myfile, $barcode_number.PHP_EOL);
    fwrite($myfile, "\n");

    //file_put_contents($filename, "\r\n" . $barcode_number.PHP_EOL, FILE_APPEND);
    fclose($myfile);
    //echo "wrote " . $barcode_number . "to " . $filename; die();

Expected output is:

123456
123457
123458

actual output is:

123458
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
unko19
  • 13
  • 2

1 Answers1

0

Your file_put_contents() call is formatted correctly, although I don't think you need the .PHP_EOL, since you're already prepending the data with "\r\n". So is your fopen()/fwrite()/fclose(). Is it possible that another script is opening this file, and thus locking the file?

Pat
  • 78
  • 2
  • 14
  • This was exactly it. I was initially opening the file with write and didn't close it. So there was some over writing issues – unko19 Jul 07 '19 at 17:19