Forum


Replies: 4   Views: 3339
Corruption of multipage template
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by stevea  · 18-05-2012 - 17:59

I am currently working with a template that has 2 pages in it and am using the following to populate the $VARIABLES$ within the template:

[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?