fopen($handle, 'w+');
I'm looking to open a .CSV file, read each row and do something with a database, and then truncate the .CSV file and write something like
This file has been read.
w+ implies Read/write but the file is also truncated. So what's the point of the read if fopen w+ will just erase what's in it?
Use a+
From the documentation:
'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With