Postprocessing of documents returned by Template class before moving to final destination
This commit is contained in:
Roman Syroeshko 2014-01-17 00:02:09 -08:00
parent 029de3183a
commit 3cd60f76de

View File

@ -117,14 +117,9 @@ class PHPWord_Template
/** /**
* Save Template * Save Template
* *
* @param string $strFilename * @return string
*/ */
public function save($strFilename) public function save() {
{
if (file_exists($strFilename)) {
unlink($strFilename);
}
$this->_objZip->addFromString('word/document.xml', $this->_documentXML); $this->_objZip->addFromString('word/document.xml', $this->_documentXML);
// Close zip file // Close zip file
@ -132,6 +127,21 @@ class PHPWord_Template
throw new Exception('Could not close zip file.'); throw new Exception('Could not close zip file.');
} }
rename($this->_tempFileName, $strFilename); return $this->_tempFileName;
} }
}
/**
* Save Template As...
*
* @param string $strFilename
*/
public function saveAs($strFilename) {
$tempFilename = $this->save();
if (file_exists($strFilename)) {
unlink($strFilename);
}
rename($tempFilename, $strFilename);
}
}