首頁  >  文章  >  後端開發  >  php读取与下载csv文件的示例代码

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

WBOY
WBOY原創
2016-07-25 08:55:25918瀏覽
  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;
复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn