Files
dev-chiefworks f76abffdcd first commit
2022-05-31 16:21:53 -04:00

23 lines
700 B
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
function export($r, $name = 'download') {
set_time_limit(0);
$filename = $name . "-" . date("Y-m-d-H-i-s") . ".csv";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $filename . '"');
header('Cache-Control: max-age=0');
$i = 0;
if (ob_get_contents()) ob_end_clean();
$out = fopen('php://output', 'w');
while ($row = $r->unbuffered_row()) {
$f = (array) $row;
if ($i == 0) {
fputcsv($out, array_keys($f), ",");
}
fputcsv($out, array_values($f), ",");
$i++;
}
fclose($out);
}