I am trying to dynamically change an image in my template. I have added a placeholder image and right-clicked, went to the web tab, and added my tag to the alt text.
My directory structure is root/site/index.php and my images are at root/public/images/pharmacy_logos/image.jpg, and here is the code I am using:
[code]
require $_SERVER['DOCUMENT_ROOT']. "/public/phpdocx/classes/CreateDocx.inc";
error_reporting(E_STRICT);
ini_set('display_errors', 1);
$data = array('employee'=> $employee->get_full_name(), 'date' => date('m/d/Y'), 'department'=>ucwords(strtolower($employee->get_department_name()))); //these are constant values
$docx = new CreateDocx(); //instantiates document object for use on subsequent pages.
$url = explode('/',req('q'));
$template = $url[count($url)-1]; //This give me the template name properly
$filename = $employee->get_employee_id() . $template;
$docx->addTemplate(DOC_LOCATION . '/templates/' . $template . ".docx"); //set the word doc template
$docx->setTemplateSymbol('~'); //use the ~ as the variable delimiter because $ is used in some templates
$docx->setDefaultFont('Century Gothic');
$vars = $docx->getTemplateVariables(); //get the defined variables on the template
$docx->addTemplateImage('logo', $_SERVER['DOCUMENT_ROOT'] . '/public/images/pharmacy_logos/29.jpg'); //this is statically set for testing
foreach ($vars['document'] as $k => $v) //compare the template variables to the keys of the data array
{
if (array_key_exists($v, $data))
{
//echo "setting $v to " . $data[$v] . '<br />';
$docx->addTemplateVariable($v, $data[$v], array());
}
}
$docx->createDocxAndDownload($filename);
[/code]
everything is working perfectly except for the image swapping. Additionally, I tried to use your image example and it worked, so it is not a server problem. Do I need to do more than just add the tag to the alt-text or something?