0

The first line saves fine and in subsequent calls the additional text appends perfectly when run locally but when run on the server only the first line saves and then seems to ignore all following attempts to save. Even if the file on the server is deleted and then I attempt to save for the 'first' time it brings back the original line that was saved the first time the file was created.

$file = 'sentQuotes-' . date("dmy") .'.txt';
$addNewQuote = "\r\n" .date("d/m/y") ."\t" .$email ."\t" .$qty ."\t" .$scent ."\t" .$customerPrice;
// the LOCK_EX flag to prevent anyone else writing to the file at the same time
file_put_contents($file, $addNewQuote, FILE_APPEND | LOCK_EX);

unset($addNewQuote);
Andrea
  • 41
  • 2
  • 1
    Any errors present? Turn on error reporting at the top of your script - `ini_set('display_errors', 1); error_reporting(-1);` and let us know if there's anything in your php error logs too – Darren Jun 30 '16 at 00:04

1 Answers1

4

I'm afraid it ended up being a case of caching!

I was on the server looking at the error logs and when I decided to check the file on the server directly noticed all of the data had been saved correctly. Turns out my local machine's ftp method (I was just using windows explorer) was caching the file instead of serving me the more up to date version. I downloaded the Filezilla client and it's absolutely fine now.

Apologies for the apparent waste of time!

Andrea
  • 41
  • 2
  • Not a waste of time at all! It turned out to be a time saver for me :) The code worked fine when I deployed it but would stopped working later on without any errors. Few weeks after it worked again and then stopped working again! It was because our wordpress host caches URL heavily. And purging the cache made the code worked for sometime. – Jags Jul 21 '16 at 19:15