Ok, so I'm having difficulty with the PHPWord class which can be found: http://phpword.codeplex.com
The weird thing about it is when I use this same code in the "example" file it works fine in generating. When I don't force a download using headers the file will open up just fine. Using this code though with the headers is causing it when it downloads to throw errors in the word file saying the file is corrupt and can't be opened, but then it opens up just fine.
public function export()
{
// Load PHPWORD Library
$this->load->library('PHPWord');
$sec = $this->phpword->createSection($secStyle);
$header = $sec->createHeader();
$header->addWatermark('images/CC_watermark.png', array('marginTop'=>1015, 'marginLeft'=>-80));
$resultSelected = $this->input->post('cbox');
foreach($resultSelected as $row)
{
$sec->addText($row);
echo $row."<br>";
}
$fileName = "Plan_Generate_".date('Ymd').".docx";
// Force Download
$filePath = $fileName;
$fileName = basename($filePath);
// $fileSize = filesize($filePath);
// Output headers.
header("Cache-Control: private");
header("Content-Type: application/stream");
// header("Content-Length: ".$fileSize);
header("Content-Disposition: attachment; filename=".$fileName);
// Output file.
// readfile ($filePath);
// exit();
// Save File
// $fileName = "files/SomethingNew_".date("Ymd").".docx";
$objWriter = PHPWord_IOFactory::createWriter($this->phpword, 'Word2007');
$objWriter->save('php://output');
}
This is the code i'm using when trying to generate the file. The trouble I'm having is it's throwing an error when it tries to force download. Thanks for any help! Ask questions if you don't fully understand the question.
Update:
Here's the image of the error's I'm receiving. Thanks for the quick responses and I'm actually going to try the Codeigniters way of doing it Tomm. morning.