I have a function which currently creates a file and stores it in a folder on my server.
I want to continue doing this but I also want it to force to download.
This is the function:
// Generates a filename and writes a CSV with a timestamped name
function putAsCSV($data_list,$account_name,$timeframe){
$date = date('d-m-Y-h-i-A');
$filename = $timeframe.'-'.$account_name.'-'.$date;
$fp = fopen('../exports/'.$filename.'.csv', 'w');
foreach ($data_list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
}
How can I make it download this file as well as storing it?
Do I need to store it in some sort of temporary file?
How can I ensure it doesn't open in the browser and actually downloads?