Skip to content

Commit

Permalink
CSV lib (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Dec 21, 2017
1 parent fd85544 commit 2d51174
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/csv.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

function array2csv(array &$array) {
if (count($array) == 0) {
return null;
}
ob_start();
$df = fopen("php://output", 'w');
foreach ($array as $row) {
fputcsv($df, $row);
}
fclose($df);
return ob_get_clean();
}

function download_send_headers($filename) {
// disable caching
$now = gmdate("D, d M Y H:i:s");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");

// force download
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");

// disposition / encoding on response body
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
}

?>

0 comments on commit 2d51174

Please sign in to comment.