Clear previous output when openToBrowser() called

If any character has been outputted before, the generated file will be corrupted.
This commit is contained in:
Adrien Loison 2016-06-07 19:09:10 -07:00
parent cd38ba093e
commit 643d1e102f
2 changed files with 15 additions and 0 deletions

View File

@ -252,6 +252,17 @@ class GlobalFunctionsHelper
header($string); header($string);
} }
/**
* Wrapper around global function ob_end_clean()
* @see ob_end_clean()
*
* @return void
*/
public function ob_end_clean()
{
ob_end_clean();
}
/** /**
* Wrapper around global function iconv() * Wrapper around global function iconv()
* @see iconv() * @see iconv()

View File

@ -121,6 +121,10 @@ abstract class AbstractWriter implements WriterInterface
$this->filePointer = $this->globalFunctionsHelper->fopen('php://output', 'w'); $this->filePointer = $this->globalFunctionsHelper->fopen('php://output', 'w');
$this->throwIfFilePointerIsNotAvailable(); $this->throwIfFilePointerIsNotAvailable();
// Clear any previous output (otherwise the generated file will be corrupted)
// @see https://github.com/box/spout/issues/241
$this->globalFunctionsHelper->ob_end_clean();
// Set headers // Set headers
$this->globalFunctionsHelper->header('Content-Type: ' . static::$headerContentType); $this->globalFunctionsHelper->header('Content-Type: ' . static::$headerContentType);
$this->globalFunctionsHelper->header('Content-Disposition: attachment; filename="' . $this->outputFilePath . '"'); $this->globalFunctionsHelper->header('Content-Disposition: attachment; filename="' . $this->outputFilePath . '"');