Return to Snippet

Revision: 45578
at May 4, 2011 08:18 by kendsnyder


Initial Code
<?php

function sendCsv($data, $filename) {
	$fp = fopen('php://output', 'w');
	ob_start();
	foreach ($data as $r) {
		fputcsv($fp, $r);
	}
	$contents = ob_get_clean();
	fclose($fp);
	header('Content-type: application/octet-stream');
	header("Content-Disposition: attachment; filename=\"$filename\"");
	echo $contents;
	exit;
}

Initial URL

                                

Initial Description

                                

Initial Title
Send Data as CSV File

Initial Tags

                                

Initial Language
PHP