php read csv to achieve csv file download function
- 2020-11-30 08:12:33
- OfStack
Paragraph 1 is read file, download.
Paragraph 2 is the string download.
<?php
$fileName = "prefs.csv";
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $fileName);
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($fileName));
readfile($fileName);
<?php
$fileName = "pref_" . date("YmdHis") . ".csv";
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $fileName);
echo $csv;