Corrupted download of 2003 xls

Topics: Developer Forum
Aug 2, 2010 at 9:03 PM
Edited Aug 2, 2010 at 9:26 PM

Got a weird problem I hope someone can help me with. I can run the 01simple-download-xls.php example without any problem. But when I add the code to my PHP webpage it gets corrupted.

I am using a form that contains a button to call the download of the xls file. The form calls back the itself so that (in the future) different data for the xls file can be generated and downloaded. My problem is that the download seems to be corrupted.

In doing some investigation I've determined:

1) As I said, the 01simple-download-xls.php

2)I can save the xls file on the server side using...

// Redirect output to a client’s web browser (Excel5) 
header('Content-Type: application/vnd.ms-excel'); 
header('Content-Disposition: attachment;filename="Arena_Report.xls"'); 
header('Cache-Control: max-age=0'); 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 
$objWriter->save('testKAM.xls'); 
readfile("testKAM.xls"); 
exit;

And the file on the server (testKAM.xls) is fine - no corruption. But the downloaded file is corrupted.

3)The corruption from the above is exactly the same as the corruption from a regular code that directs the php to stdout

// Redirect output to a client’s web browser (Excel5) 
header('Content-Type: application/vnd.ms-excel'); 
header('Content-Disposition: attachment;filename="Arena_Report.xls"'); 
header('Cache-Control: max-age=0'); 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 
$objWriter->save('php://output'); 
exit; 

So somehow the act of downloading seems to be messing up somehow. Does anyone have any ideas for me to try?

I am using PHPExcel 1.7.3c, PHP 5.2.12 on an Linux server ver 2.6, with Apache and zip:

Zip enabled 
Extension Version $Id: php_zip.c 287723 2009-08-26 02:16:41Z guenter $ Zip 
version 1.8.11 
Libzip version 0.9.0 

Thanks, Kevin

Aug 9, 2010 at 6:59 PM
Can anyone help here? Or is more info required? Kevin
Coordinator
Aug 20, 2010 at 12:17 PM

Can you try opening the corrupted file in a standard text editor, and see if there are any obvious text strings displayed (e.g. error messages)

Aug 20, 2010 at 7:47 PM

Mark,

Thanks for the help.   I had already opened the file up in notepad++ with no joy - whole bunches of y's with double dots on top though, it then goes on with the entire HTML page created from the PHP. So I have now decided to go another route.  When I first wrote this discussion I had put the PHPExcel code within my PHP code at the very beginning before anything was outputted.  I presumed that something was in the output buffered that was screwing things up. Therefore I went a different route.

Now I have created a form with a single button that calls the PHPExcel file by itself without any of the webpage code around.  Something like....

<form action="reports/simple-download-xls.php" method="get">
  <input type='submit' name='schedulereport' id='schedulereport' value='Schedule Report' />
</form>

and the simple-download-xls.php can almost mirror the examples perfectly.  Plu,s using the get, I can pass variables into the file reasonably well.  It's a pity that I wasn't able to get the corruption sorted out - maybe after I finish the whole website I can come back and re-address this issue.   I really like this library and think it is really great.

I really can't put here what the corruption is because I can't copy it (The 9th char is a null ) and I can't give you a screen shot as I can't attach a pic. So sorry.....

Thanks for everything.   If you have any other ideas for checking what the corruption could be please tell me.

Kevin

Mar 2, 2011 at 8:22 AM

Hi Kevin,

Did you solve downloaded file is corrupting problem.

I'm also have the same problem same as you.

Anyone help me.

 

Thanks in advance,

thenndral.

 

 

Mar 2, 2011 at 8:22 AM

Hi Kevin,

Did you solve downloaded file is corrupting problem.

I'm also have the same problem same as you.

Anyone help me.

 

Thanks in advance,

thenndral.

 

 

Sep 20, 2013 at 8:29 AM
Hello all,

I have the problem as you, two days I search solution, but can`t find it.

If anyone have a solution for this problem I will be happy to share it.
Sep 20, 2013 at 9:50 AM
I FIND THE SOLUTION OF MY PROBLEM!!!!!

Just must clean the buffer before settin the header part like this:

if (ob_get_contents()) ob_end_clean();