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

PHP直接下载CSV文件

PHP中文网
Release: 2016-05-25 17:00:23
Original
1095 people have browsed it

用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);
Copy after login

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;
Copy after login


Related labels:
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template