PHP Classes

exporting a stream as the file

Recommend this page to a friend!

      MS-Excel Stream Handler  >  All threads  >  exporting a stream as the file  >  (Un) Subscribe thread alerts  
Subject:exporting a stream as the file
Summary:Any ideas on using this class to export a stream as the file
Messages:2
Author:Steven
Date:2008-07-21 09:03:32
Update:2008-07-21 17:10:20
 

  1. exporting a stream as the file   Reply   Report abuse  
Picture of Steven Steven - 2008-07-21 09:03:32
Any ideas on using this class to export a stream as the excel file and not ever saving/writing the file to the apache server? If not, how can I be sure that the file will get deleted after the download? Any thoughts?

  2. Re: exporting a stream as the file   Reply   Report abuse  
Picture of Steven Steven - 2008-07-21 17:10:21 - In reply to message 1 from Steven
Ok, is there any flaw in this approach that would leave these files hanging around?

require_once "excel.php";
$export_file = "tmp/example.xls";
$fp = fopen("xlsfile://".$export_file, "wb");
// typically this will be generated/read from a database table
$assoc = array(
array("Sales Person" => "Sam Jackson", "Q1" => "$3255", "Q2" => "$3167", "Q3" => 3245, "Q4" => 3943),
array("Sales Person" => "Jim Brown", "Q1" => "$2580", "Q2" => "$2677", "Q3" => 3225, "Q4" => 3410),
array("Sales Person" => "John Hancock", "Q1" => "$9367", "Q2" => "$9875", "Q3" => 9544, "Q4" => 10255),
);

fwrite($fp, serialize($assoc));
fclose($fp);
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("Content-type: application/x-msexcel");
header ("Content-Disposition: attachment; filename=\"MMTSserialnumbers.xls\"" );
header ("Content-Description: PHP/INTERBASE Generated Data" );
readfile("xlsfile://".$export_file);
unlink("/".$export_file);