欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-16 22:57:47
...
  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;
复制代码