Home  >  Article  >  Backend Development  >  PHP uses header to save excel files_PHP tutorial

PHP uses header to save excel files_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:59:271245browse

A simple file download using the header() function. We briefly explained the excel operation tutorial. Friends in need can refer to it.

The code is as follows
 代码如下 复制代码

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

Copy code


header("Content-type:application/vnd.ms-excel");
 代码如下 复制代码

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

header("Content-Disposition:attachment;filename=test_data.xls");

Example
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