fputs overwrites first line is csv

379 Views Asked by At

Here is my code that writes to the CSV. My issue is that it's overwriting the top line of my csv file. Is there some way to go about doing this different? I want to add the new data to the beginning of the csv without overwriting anything that's already there.

    // Send Routine 
    $filename="contact.csv";
    $datfile=fopen($filename, 'r+');
            spamcheck($EReply);     
            $ESubject=$Subject;

//          $EMessage = $MsgHeader;
            $EMessage = "Form Submission:\r\n";
            for(reset($FormField); $key=key($FormField); next($FormField)) {
                spamcheck($FormField[$key]);
                $EMessage .= $key.": ".$FormField[$key];
//              $EMessage .= "<br><br>\r\n";
                $EMessage .= "\r\n";
                $datachunk="\"".$FormField[$key]."\",";
                fputs($datfile, $datachunk);
            }
    fputs($datfile, "\r\n");
    fclose($datfile);
0

There are 0 best solutions below