PHP Classes

Output to Browser

Recommend this page to a friend!

      Excel Writer  >  All threads  >  Output to Browser  >  (Un) Subscribe thread alerts  
Subject:Output to Browser
Summary:A new method to send generated xls file to browser
Messages:2
Author:Jim Katz
Date:2010-04-29 20:13:53
Update:2012-01-05 15:54:21
 

  1. Output to Browser   Reply   Report abuse  
Picture of Jim Katz Jim Katz - 2010-04-29 20:13:53
I added this method to output my XLS file to the browser:
function output(){
$this->fp = @fopen($this->fileName,"r");
$this->buffer = fread($this->fp,filesize($this->fileName));
header('Content-Type: application/xls');
if(headers_sent())
echo ('Some data has already been output to browser, can\'t send XLS file');
header('Content-Length: '.strlen($this->buffer));
header('Content-disposition: inline; filename="'.$this->fileName.'"');
fclose($this->fp);
unlink($this->fileName);
echo $this->buffer;
}

$this->fileName is assigned in the constructor.
I call $this->output() after the call to fclose in the close method. To clean up the server I call unlink.

  2. Re: Output to Browser   Reply   Report abuse  
Picture of Geoff Stacey Geoff Stacey - 2012-01-05 15:54:21 - In reply to message 1 from Jim Katz
I am quite new to php. What is the code that you put into the calling php? I tried

$this->filename;
$this->output();

but get an error in the first line:

Fatal error: Using $this when not in object context in...