PHP Classes

Awful

Recommend this page to a friend!

      MS-Excel Stream Handler  >  All threads  >  Awful  >  (Un) Subscribe thread alerts  
Subject:Awful
Summary:Package rating comment
Messages:11
Author:Nick Howarth
Date:2009-08-13 09:22:36
Update:2009-11-04 03:46:22
 

Nick Howarth rated this package as follows:

Utility: Bad
Consistency: Sufficient
Documentation: Bad
Examples: Sufficient
  1 - 10   11 - 11  

  1. Awful   Reply   Report abuse  
Picture of Nick Howarth Nick Howarth - 2009-08-13 09:22:36
Awful

  2. Re: Awful   Reply   Report abuse  
Picture of Ignatius Teo Ignatius Teo - 2009-08-14 05:32:20 - In reply to message 1 from Nick Howarth
Great! Can you say why?

  3. Re: Awful   Reply   Report abuse  
Picture of John Ralph John Ralph - 2009-11-01 21:42:40 - In reply to message 2 from Ignatius Teo
While I wouldn't call it awful, I am having a problem. I included the header lines to send output to the browser as a file. Every header(...); line generates a php error stating that headers were already sent by excel.php. I can't even use a header statement to kick the user over to the directory where I'm creating the output.

  4. Re: Awful   Reply   Report abuse  
Picture of Ignatius Teo Ignatius Teo - 2009-11-01 22:39:18 - In reply to message 3 from John Ralph
Hi John,

excel.php does not send any headers. Can you post some example code of what you're trying to do?

  5. Re: Awful   Reply   Report abuse  
Picture of John Ralph John Ralph - 2009-11-02 03:22:11 - In reply to message 4 from Ignatius Teo
Sure...I modified the example code you had posted on the 999tutorials site as below:


include ("./excel.php"); //Changed to include thinking it would work better

$export_file = "xlsfile://[removed]/registration/files/".$output_file;
$file_handle = fopen($export_file, "wb");

if(!is_resource($file_handle)) die("Error opening file for writing.");

$assoc = array();
// Loop on retrieved records
while ($drow = mysql_fetch_assoc($dresult)){
// add each record to the output array
$assoc[] = $drow;
}
fwrite($file_handle,serialize($assoc));
fclose($file_handle);

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=\"".basename($export_file) . "\"" );
header ("Content-Description: PHP/INTERBASE Generated Data" );
readfile($export_file);

When I run this, I get an error output for each of the "header" statements:

Warning: Cannot modify header information - headers already sent by (output started at /[truncated]/registration/excel.php:235) in /[truncated]/registration/export.php on line 111

Maybe I'm wrong in assuming that the error msg is actually implicating excel.php - I certainly didn't see any "header()" pragmas in there.

  6. Re: Awful   Reply   Report abuse  
Picture of Ignatius Teo Ignatius Teo - 2009-11-02 03:47:31 - In reply to message 5 from John Ralph
> headers already sent by (output started at /[truncated]/registration/excel.php:235) in /[truncated]/registration/export.php on line 111

Ah... is there anything being dumped to stdout at or around line 235 in excel.php? Because you're including excel.php, it gets parsed AND executed first. You could try require_once 'excel.php'; instead, or just get rid of any print/echo/print_r debugging statements after the class definition.

  7. Re: Awful   Reply   Report abuse  
Picture of John Ralph John Ralph - 2009-11-02 12:13:36 - In reply to message 6 from Ignatius Teo
Yes, that was my thought. The last bit of excel.php is:

stream_wrapper_register("xlsfile", "xlsStream")
or die("Failed to register protocol: xlsfile");
?>

and there is nothing writing to stdout in my export.php until after the close tag for php:

<!DOCTYPE html public "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<META name="robots" content="noindex, nofollow">
<TITLE>Registration</TITLE>
</HEAD>
<body>
<a href="./files/<?=$output_file?>">Click here for your file</a><br>
<a href="/registration/event_dump.php">Click here </a>to return to the export page.
</body>
</html>

That last bit was added because I couldn't get the other to work properly.

  8. Re: Awful   Reply   Report abuse  
Picture of Ignatius Teo Ignatius Teo - 2009-11-02 22:46:49 - In reply to message 7 from John Ralph
Hi John,

It's hard to tell without seeing the rest of the code. You could try forcing an ob_end_clean() before the headers.

...
fclose($file_handle);
ob_end_clean();

header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
...

  9. Re: Awful   Reply   Report abuse  
Picture of John Ralph John Ralph - 2009-11-02 23:10:53 - In reply to message 8 from Ignatius Teo
I sent my entire .php directly to you.

I'm wondering if this isn't caused by some server setting over which I have no control?

  10. Re: Awful   Reply   Report abuse  
Picture of John Ralph John Ralph - 2009-11-04 03:26:25 - In reply to message 9 from John Ralph
My messages are now on the "IE 6 and 7 unable to download generated xls" thread.

 
  1 - 10   11 - 11