Need to process large csv files with php. Working with fgetcsv and performance seems pretty good. For even better/ faster processing I would like the csv files to have column names on the first row, which are missing right now.
Now I would like to add a top row with columns names to the csv file with PHP before processing the files with fgetcsv.
Is there a way to add a line top the top of the file with php easily? Or would this mean I have to take a approach like below?
- List item
- List item
- create a temp file
- add the column names to this temp file
- read original csv file contents
- put original csv contents into the temp file
- delete original file
- rename the temp file
Any feedback on how to do this in the most effective way is highly appreciated. Thanks for your time :)