Skip to content

Instantly share code, notes, and snippets.

@nurullahisik
Created July 8, 2019 10:45
Show Gist options
  • Save nurullahisik/0ac4c69b94305499427f66b8d1bf0b2c to your computer and use it in GitHub Desktop.
Save nurullahisik/0ac4c69b94305499427f66b8d1bf0b2c to your computer and use it in GitHub Desktop.
<?php
$file_name = "data.csv";
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Type: application/csv");
$file = fopen('php://output', 'w');
$header = array(
"ID", "NAME", "SURNAME", "JOB"
);
fputcsv($file, $header);
$data = array(
array(1, "Test 1", "1", "Computer Engineer1"),
array(2, "Test 2", "2", "Computer Engineer2"),
array(3, "Test 3", "3", "Computer Engineer3"),
array(4, "Test 4", "4", "Computer Engineer4"),
array(5, "Test 5", "5", "Computer Engineer5"),
array(6, "Test 6", "6", "Computer Engineer6"),
);
foreach ( $data AS $item ){
fputcsv($file, $item);
}
fclose($file);
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment