i have php file creates csv file... however. contents of csv file include entire html page well.
here's result:
number, access code, date 1, 1bis1b1165n8xba, 29/01/2016 2, 1bipa%1166vwg&m, 29/01/2016 3, 1bikes11677ghk0, 29/01/2016 4, 1bix$t11682w&&@, 29/01/2016 5, 1biq2n1169npon5, 29/01/2016 <!doctype html> <html dir="ltr" lang="en" xml:lang="en"> <head> ... ... ... </html>
here's code.
ob_clean(); $filename="export.csv"; header('pragma: public'); header('expires: 0'); header('cache-control: must-revalidate, post-check=0, pre-check=0'); header('cache-control: private', false); header('content-type: text/csv'); header('content-disposition: attachment;filename=' . $filename); if(isset($associated_array['0'])) { $fp = fopen('php://output', 'w'); fputcsv($fp, array_keys($associated_array['0'])); foreach($associated_array $values){ fputcsv($fp, $values); } fclose($fp); } ob_flush();
i've closed file , i've flushed buffer have gone wrong please?
cheers
dave
if want send csv file client should exit script after delivering data.
... ob_flush(); exit();
if don't exit()
or die()
output of script added csv file @ client side.
Comments
Post a Comment