$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); 复制代码 例2,字符串形式下载csv文件。 $fileName = "pref_" . date("YmdHis") . ".csv"; header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $fileName); echo $csv; 复制代码