php利用header保存excel文件

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

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

实例代码如下:

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