fputcsv seems to be producing garbage

223 Views Asked by At

Could someone let me know what I've missed here.

I have this CSV producing code:

    //for loop generating non empty $output array
    fputcsv($file, $output, ',', '"');
            }//end of for
            fclose($file);

        ob_clean();
        flush();
        header('Content-Description: File Transfer');
        header('Content-Type:text/csv;charset=UTF-8');
        header('Content-Disposition: attachment; filename='.basename(getcwd().'../../../tmp/signup_download.csv'));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0'); 
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize(getcwd().'../../../tmp/signup_download.csv'));
        readfile(getcwd().'../../../tmp/signup_download.csv');
        exit;

While it appears to be generating a reasonable result in a plain text editor like notepad, opening in openoffice just produces garbage.

Heres a sample of the created csvs:

test2,test2,[email protected],1234,Swindon,december_2014

I suspect the problem is somehow in the fputcsv statement as the file otherwise generates and downloads fine.

0

There are 0 best solutions below