Line feed in output buffer after dispatch
Using the Zend Framework, I wanted to send a file. But when doing so from my controller I noticed a LineFeed allready sent:
The following code:
$data = 'Let me test this';
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filena开发者_StackOverflowme="output.txt";' );
//header('Content-Length: '.strlen($data));
ob_clean(); flush();
die($data);
Will give me the output.txt file:
[LF]
Let me test this
I have a preDispatch plugin, but I tried with the test code before exiting it, and the LF wasn't outputted yet. And all controller-files starts with <?php
. without any LF first.
So, my question is:
- What happens between preDispatch plugins are run and the controller is dispatched? .. or even better: How can I find out where the LineFeed is outputted?
I have tested your code with an empty preDispatch()
method in a Zend_Controller_Plugin_Abstract
derived plugin, and I don't get any LF in the output. I do get it, however, if I add echo "\n"
explicitly into the preDispatch()
method body.
So, chances are that your plugin is outputting the LF somewhere else. Maybe you are using a closing tag in your plugin? (just to discard possibilities).
For files that contain only PHP code, the closing tag ("?>") is never permitted. It is not required by PHP, and omitting it´ prevents the accidental injection of trailing white space into the response.
(in the Zend Framework Coding Standard)
精彩评论