php利用header保存excel文件

作者:袖梨 2022-06-24
 代码如下 复制代码

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

相关文章

精彩推荐