Skip to content

Instantly share code, notes, and snippets.

@hmboyd
Created December 29, 2021 00:34
Show Gist options
  • Save hmboyd/9c0549d84aa800383ff6b4b6a2977c42 to your computer and use it in GitHub Desktop.
Save hmboyd/9c0549d84aa800383ff6b4b6a2977c42 to your computer and use it in GitHub Desktop.
<?php
$delimiter = ";";
$filename = "example_" . date('Y-m-d H:i:s') . ".csv";
$f = fopen('php://memory', 'w');
// intestazione
$intestazioni[] = "ID";
$intestazioni[] = "NOME";
$intestazioni[] = "COGNOME";
$intestazioni[] = "CODICE FISCALE";
$intestazioni[] = "CITTà";
fputcsv($f, $intestazioni, $delimiter);
// dati
$rowData = array();
$rowData[] = "00001";
$rowData[] = "Mario";
$rowData[] = "Rossi";
$rowData[] = "AGGCNSHDHDJ";
$rowData[] = "Milano";
fputcsv($f, $rowData, $delimiter);
fseek($f, 0);
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $filename . '";');
fpassthru($f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment