Echoing to screen when using headers to output to csv
<p>I have a PHP application which generates a set of codes , saves them to MySQL DB and then outputs the same to the user as a downloadable csv file. I also have an echo statement after the code block to convert the PHP array to csv. The echo statement after the convert_to_csv function call instead of outputting to the browser outputs to the file instead and overwrites the first line.  How do I get the echo statement to output to the browser instead?  The code block is below:</p>

<pre><code>convert_to_csv($newCodesArray,$fileName,',');
echo "Your file was successfully generated";

function convert_to_csv($input_array, $fileName, $delimiter)
{

    header('Content-Type: text/csv');
    header("Content-Disposition: attachment; filename=\"$fileName\"");
    $f = fopen('php://output', 'w');
    /* loop through array  */
    foreach ($input_array as $line) {
        /* default php csv handler */
        fputcsv($f, $line, $delimiter);
    }
    fclose($f) or die("Can't close php://output");

}
</code></pre>