php读取与下载csv文件的示例代码
时间:2021-07-01 10:21:17
帮助过:32人阅读
- $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);
例2,字符串形式下载csv文件。
- $fileName = "pref_" . date("YmdHis") . ".csv";
- header('Content-Type: application/octet-stream');
- header('Content-Disposition: attachment; filename=' . $fileName);
- echo $csv;
|