Using the following code I’m saving a .csv file on the server
foreach($list as $item)
{
$csv .= join("\t", $item) . "\r\n";
}
$csv = chr(255).chr(254).mb_convert_encoding($csv,"UTF-16LE","UTF-8");
header("Content-type: application/x-msdownload");
header("Content-disposition: csv; filename=CSV_".date("YmdHis").".csv; size=".strlen($csv));
$filename='CSV_'.$dateTimeNow.".csv";
file_put_contents($filename, $csv); // Create temp file
The .csv is successfully saved but the client is still receiving a download dialogue. How can I stop the download dialogue from showing?
If the CSV file is not intended to be sent to the client system, then you should not be setting headers that imply that you’re sending a .csv file to the client i.e. remove the
headerlines that causes this response to the client.