当前位置:Gxlcms > PHP教程 > php读取与下载csv文件的示例代码

php读取与下载csv文件的示例代码

时间:2021-07-01 10:21:17 帮助过:32人阅读

  1. $fileName = "prefs.csv";
  2. header('Content-Type: application/octet-stream');
  3. header('Content-Disposition: attachment; filename=' . $fileName);
  4. header('Content-Transfer-Encoding: binary');
  5. header('Content-Length: ' . filesize($fileName));
  6. readfile($fileName);

例2,字符串形式下载csv文件。

  1. $fileName = "pref_" . date("YmdHis") . ".csv";
  2. header('Content-Type: application/octet-stream');
  3. header('Content-Disposition: attachment; filename=' . $fileName);
  4. echo $csv;

人气教程排行