Download xlsx file from server not working

Topics: User Forum
Mar 7, 2012 at 12:52 PM

Hello,

I'm curently tranferring some scripts that use PHPExcel from a Windows to a Linux server.

On the Linux machine I ran into the following problem:

If I download the created xlsx-file [$objWriter->save('php://output');] directly from the server, Excel complains about a wrong format and is unable to open it.

If, on the other hand I save the file to the server disk [$objWriter->save('file.xlsx');] and download this file to client, evrything works as expected.

So what may couse this problem?

Gerhard

 

 

 

Coordinator
Mar 7, 2012 at 4:26 PM

The most likely cause is that something somewhere in your script is echoing additional output. The easiest way to identify this is to open the output in a text editor, and look for additional characters (often white space, newlines or similar) at the beginning and end of the file, or for any obvious PHP-style error messages in the file (e.g headers already sent)

Mar 8, 2012 at 5:54 AM

Yes, you are right. On transferring the scripts from one server to an other, my collegue made some "updates" to our common include-files (database names, etc.). And one of this scripts echoed a few empty lines.

Interesting thing is still: why did it work when I saved the file to the server disk and transferred id manually to the client and not when downloading it directly?

 

 

Mar 8, 2012 at 7:14 AM

if you save it to disk first, the empty lines get echoed to the browser, while the excel file gets written to the disk without the empty lines. Therefor your excel file is not corrupted.