File tree Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -63,18 +63,20 @@ class PHPWord_Template {
63
63
* @param string $strFilename
64
64
*/
65
65
public function __construct ($ strFilename ) {
66
- $ path = dirname ($ strFilename );
67
- $ this ->_tempFileName = $ path .DIRECTORY_SEPARATOR .time ().'.docx ' ;
66
+ $ this ->_tempFileName = tempnam (sys_get_temp_dir (), '' );
67
+ if ($ this ->_tempFileName !== false ) {
68
+ // Copy the source File to the temp File
69
+ if (!copy ($ strFilename , $ this ->_tempFileName )){
70
+ throw new PHPWord_Exception ('Could not copy the template from ' .$ strFilename .' to ' .$ this ->_tempFileName .'. ' );
71
+ }
68
72
69
- // Copy the source File to the temp File
70
- if (!copy ($ strFilename , $ this ->_tempFileName )){
71
- throw new PHPWord_Exception ('Could not copy the template from ' .$ strFilename .' to ' .$ this ->_tempFileName .'. ' );
72
- }
73
+ $ this ->_objZip = new ZipArchive ();
74
+ $ this ->_objZip ->open ($ this ->_tempFileName );
73
75
74
- $ this ->_objZip = new ZipArchive ( );
75
- $ this -> _objZip -> open ( $ this -> _tempFileName );
76
-
77
- $ this -> _documentXML = $ this -> _objZip -> getFromName ( ' word/document.xml ' );
76
+ $ this ->_documentXML = $ this -> _objZip -> getFromName ( ' word/document.xml ' );
77
+ } else {
78
+ throw new PHPWord_Exception ( ' Could not create temporary file with unique name in the default temporary directory. ' );
79
+ }
78
80
}
79
81
80
82
/**
Original file line number Diff line number Diff line change 23
23
**************************************************************************************
24
24
25
25
Fixed in branch for release 0.7 :
26
- - Bugfix: (RomanSyroeshko) GH-34 - PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input
27
26
- Bugfix: (RomanSyroeshko) GH-32 - "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found
27
+ - Bugfix: (RomanSyroeshko) GH-34 - PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input
28
+ - Bugfix: (RomanSyroeshko) GH-38 - Temporary files naming logic in PHPWord_Template can lead to a collision
28
29
- Feature: (Progi1984) GH-1 - Implement RTF Writer
29
30
- Feature: (Progi1984) GH-2 - Implement ODT Writer
30
31
- Feature: (kaystrobach) - Word2007 : Add rowspan and colspan to cells
You can’t perform that action at this time.
0 commit comments