php读取csv实现csv文件下载功能

内容摘要
第一段是读文件,下载。第二段是字符串下载。
复制代码 代码如下:<?php$fileName = "prefs.csv";header('Content-Type: application/octet-stream');header('Content-Disposi
文章正文

第一段是读文件,下载。
第二段是字符串下载。

复制代码 代码如下:

<?php
$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);

复制代码 代码如下:

<?php
$fileName = "pref_" . date("YmdHis") . ".csv";
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $fileName);
echo $csv;


代码注释

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!