I am trying to generate report and upload it. Problem is that when function that generates the file ends with readfile(), it just downloads the file even if I put ob_start() before the function call. So I don't understand why ob_start is not catching It.
Problem should be here
I call
ob_start()Then I call function that outputs file like this
header('Content-Type: application/vnd.openxmlformats-officedocument.' . 'wordprocessingml.document'); header('Content-Disposition: attachment; filename="' . $fileNameDownload . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($fileName . '.' . $this->_extension)); readfile($fileName . '.' . $this->_extension);After previous function call I put
$content = ob_get_contents();
and 4. ob_end_clen()
I would expect that with readfile() the function will start to write into buffer, but instead it outputs the file for download
I believe the fact that headers are being set, and not being captured by the output buffer, that you may need to cancel them out, especially since
Content-Disposition: attachmentis setting the response to be a forced download.http://www.php.net/manual/en/function.ob-start.php
Therefore if the function sets:
you will need to do cancel it out after you've ended the output buffering capture, ie: