简体   繁体   中英

file_put_contents doesn't save appended lines when on server (php)

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);

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM