Home >Backend Development >PHP Tutorial >php文件的下载

php文件的下载

WBOY
WBOYOriginal
2016-06-23 13:43:50815browse

平时用都要用的XLS,EXCEL,Word等,一般都是提供给用户下载使用说明书,借助于php很容易就可以实现;

$filename = rtrim($_SERVER['DOCUMENT_ROOT'],'/').'/demo.csv';

header('Content-Disposition: attachment; filename=demo.xlsx');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: ' . filesize($filename));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile($filename);
同理,其他的文件也是一样的,原理很简单,就是把头部header更改以下就ok,如果不太了解php中header部分,那么请查看: 点击打开链接

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