Clear previous output when openToBrowser() called (#243)

If any character has been outputted before, the generated file will be corrupted.
This commit is contained in:
Adrien Loison 2016-06-08 13:53:41 -07:00
parent cd38ba093e
commit 8edd8e2401
2 changed files with 15 additions and 0 deletions

View File

@ -252,6 +252,17 @@ class GlobalFunctionsHelper
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()
* @see iconv()

View File

@ -121,6 +121,10 @@ abstract class AbstractWriter implements WriterInterface
$this->filePointer = $this->globalFunctionsHelper->fopen('php://output', 'w');
$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
$this->globalFunctionsHelper->header('Content-Type: ' . static::$headerContentType);
$this->globalFunctionsHelper->header('Content-Disposition: attachment; filename="' . $this->outputFilePath . '"');