Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Silex CSV generator
$app->match('/export', function() use($app) {
$records = $app['db']->fetchAll("SELECT * FROM formdata");
$file = "/tmp/formdata.csv";
$output = fopen($file, "w");
fputcsv($output, array('name','surname','province'), ',');
foreach ($records as $row)
fputcsv($output, $row, ',');
return $app->sendFile($file,200, array('Content-type' => 'text/csv'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment