Forum


Replies: 7   Views: 3286
Creating more than one docx results in corrupt files
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 hchandler  · 19-10-2011 - 02:42

After months of looking at it off and on, I am still trying to get this software to work. I did get one patch in short order. It's extremely frustrating.

I have a very simple example where I have three functions that each creates a docx. Basically a position description, exclusivity agreement and resume template for a job posting (163 in this case). I call them in order like below:

$this->create_position_docx_subs('163');
$this->create_exclusivity_template_subs('163');
$this->create_resume_template_subs('163');

Very standard stuff - I copied one below at the bottom of this message for reference. Basically just like the examples that are provided as "documentation" except I didn't see one with multiple files.

The first docx that is created is always fine - subsequent docx's are always corrupt. It doesn't matter the order that they're called - only the first docx is fine - the next two are always corrupt (and can be automatically recovered when opened in Word, but that's not very professional). So in the example above the position docx is fine and the other two are corrupt. If I call them in this order:

$this->create_resume_template_subs('163');
$this->create_position_docx_subs('163');
$this->create_exclusivity_template_subs('163');

the resume docx is fine and the other two are corrupt (becauseI created the resume docx first). If I call the PHP script three times, each time commenting two functions out like this:

$this->create_resume_template_subs('163');
//$this->create_position_docx_subs('163');
//$this->create_exclusivity_template_subs('163');

all three will work. If I comment out each of the other two function calls in subsequent script executions each document is also created fine. It's only when I try to create more than one docx at the same time that I get corruption issues. So it's not a problem with the data I'm sending to php docx. It's a problem trying to create three different docx files in the same script.

Has anyone else experience this problem or has anyone else created more than one docx in script??

This is the example:
function create_exclusivity_template_subs($post_id)
{
$excl_docx = new CreateDocx();
$excl_docx->addTemplate('doc_gen/exclusivity_template_subs.docx');

// get job info
$job_results = mysql_query("SELECT id, deadline_date, start_date, end_date, job_title,
short_description, long_description, system_id, approx_salary, approx_salary_range
FROM jb_jobs WHERE id = ".$post_id);
$job = mysql_fetch_array($job_results, MYSQL_ASSOC);

var_dump(htmlspecialchars($job['job_title']));
$excl_docx->addTemplateVariable('TITLE', htmlspecialchars($job['job_title']));

$req = $post_id." - ".$job['system_id'];
var_dump(htmlspecialchars($req));
$excl_docx->addTemplateVariable('REQ', htmlspecialchars($req));

// Create file info
$position_path = "doc_gen/subs/";
$position_name = $req." ".$job['job_title']." IUI Exclusivity Agreement";

$excl_docx->createDocx($position_path.$position_name);
$excl_docx->__destruct();
} // create_exclusivity_template_subs