[code]
$filename = 'UnitDesignTemplate-'.str_replace(' ', '', $this->rec->title);
$document = new CreateDocx();
$document->addTemplate(dirname(__FILE__).'/templates/unitdesigntemplate.docx');
$document->addTemplateVariable('LAUNCH', $this->rec->launch_time);
$document->addTemplateVariable('PLAN', $this->rec->plan_time);
$document->addTemplateVariable('RTIME', $this->rec->research_time);
$document->addTemplateVariable('DESKCRIT', $this->rec->desk_crits);
$document->addTemplateVariable('SHARE', $this->rec->publish_share);
$document->addTemplateVariable('TTIME', $this->rec->total_time);
$document->addTemplateVariable('TITLE', $this->rec->title);
...
$document->addTemplateVariable('REQUIREMENTS', $this->rec->requirements, 'html');
$document->clearBlocks();
$document->parseStyles();
$document->createDocx($filename);
[/code]
I then push the resulting docx file to the browser and remove the file from the server using:
[code]
header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document");
header("Content-Length: ".filesize($filename.'.docx'));
header('Content-Disposition: attachment; filename='.$filename.'.docx');
header('Content-Transfer-Encoding: binary');
readfile($filename.'.docx');
unlink($filename.'.docx');
[/code]
I originally did it this way because the createDocxAndDownload() function was the initial culprit as to why the Word document was coming out corrupted. However, this only worked once and since then has generated files that, when opened in Word (Office Pro Plus 2010, Word version 14.0.6112.5000 64bit), gives the error "The file is corrupt and cannot be opened."
Does anyone have a clue as to what can be going wrong here?