-
-
- $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);
Copy code
Example 2. Download the csv file in string form.
-
-
- $fileName = "pref_" . date("YmdHis") . ".csv";
- header('Content-Type: application/octet-stream');
- header(' Content-Disposition: attachment; filename=' . $fileName);
- echo $csv;
Copy code
|