php利用header保存excel文件
一个利用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);