Home  >  Article  >  php教程  >  php利用header保存excel文件

php利用header保存excel文件

WBOY
WBOYOriginal
2016-06-13 10:03:40749browse

一个利用header()函数来实例简单的文件下载,我们简单的讲解了excel的操作教程,有需要的朋友可以参考一下。

 代码如下 复制代码

header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=test_data.xls");


实例

 代码如下 复制代码

$filename = "20090210.xls";
$file = fopen(PUBLIC_EXPORT_DIR.$filename,"r"); // 打开文件
Header("Content-type:application/force-download"); 
Header("Accept-Ranges:bytes");  
header("Content-Type: application/msexcel");
Header("Accept-Length:".filesize(PUBLIC_EXPORT_DIR.$filename));  
Header("Content-Disposition:attachment;filename=".$filename);  
echo fread($file,filesize(PUBLIC_EXPORT_DIR.$filename));
fclose($file);

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