Home > Backend Development > PHP Tutorial > Sample code for php to read and download csv files

Sample code for php to read and download csv files

WBOY
Release: 2016-07-25 08:55:25
Original
988 people have browsed it
  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);
Copy code

Example 2. Download the csv file in string form.

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


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template