Home >php教程 >PHP源码 >PHP直接下载CSV文件

PHP直接下载CSV文件

PHP中文网
PHP中文网Original
2016-05-25 17:00:231156browse

用PHP代码下载CSV文件,可以是字符串,也可以是一个CSV文件。
第一段是读文件,下载。
第二段是字符串下载。

1. [代码][PHP]代码   

<?php
$fileName = "prefs.csv";
header(&#39;Content-Type: application/octet-stream&#39;);
header(&#39;Content-Disposition: attachment; filename=&#39; . $fileName);
header(&#39;Content-Transfer-Encoding: binary&#39;);
header(&#39;Content-Length: &#39; . filesize($fileName));
readfile($fileName);

2. [代码][PHP]代码   

$fileName = "pref_" . date("YmdHis") . ".csv";
header(&#39;Content-Type: application/octet-stream&#39;);
header(&#39;Content-Disposition: attachment; filename=&#39; . $fileName);
echo $csv;


Statement:
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
Previous article:php截取中文字符Next article:公司内部管理系统