PHPWord class in CodeIgniter is not generating correct, throwing errors in word file PHPWord class in CodeIgniter is not generating correct, throwing errors in word file codeigniter codeigniter

PHPWord class in CodeIgniter is not generating correct, throwing errors in word file


You should be setting headers via CodeIgniters functions, that is what could be causing the issue for you:

CI Output Class

$this->output->set_header();

Permits you to manually set server headers, which the output class will send for you when outputting the final rendered display. Example:

$this->output->set_header("HTTP/1.0 200 OK");$this->output->set_header("HTTP/1.1 200 OK");$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");$this->output->set_header("Cache-Control: post-check=0, pre-check=0");$this->output->set_header("Pragma: no-cache"); 

My assumption is you are trying to do update headers the PHP way, but you are playing by CI rules for output.


This was fixed by using CI's $this->download->force_download().

And by passing the data through ob_start(), ob_get_contents(), and ob_end_clean() for people needing help with it.


Are you sure you don't want

 header("Content-Type: application/octet-stream");

instead of just stream? What is the actual error and is it word or the browser or php that is throwing the error?

Also, CodeIgniter has a download helper to send files... You may want to try that.http://codeigniter.com/user_guide/helpers/download_helper.html