-3

Im using PHPWord to make a document from a template, its all worked great so far and the documentation is fairly decent: http://phpword.readthedocs.org/en/latest/index.html

But I cannot open the file that I have created, using:

$templateProcessor->saveAs($filename);

It says word cannot open as user does not have access privileges. I don't see anything in the documentation about this and searching SO finds several other similar questions all unanswered.

Anyone have any ideas on this?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Ben Rhys-Lewis
  • 3,118
  • 8
  • 34
  • 45
  • Does it says about contact the administrator? – Neobugu Feb 11 '16 at 15:19
  • 1
    No just: Word cannot open the document: user does not have access privileges. The help box says its been saved with permissions but no idea how not to save with permissions. Maybe I shall just try and find a different php to docx library instead – Ben Rhys-Lewis Feb 11 '16 at 15:42

2 Answers2

1

You can do this manually I think : http://php.net/manual/en/function.chmod.php

// Read and write for owner, read for everybody else
chmod("/somedir/somefile", 0644); 
John Smith
  • 319
  • 3
  • 11
1

Ok I worked it out. Thanks to @John Smith for helping to steer me in the right direction. I found the answer here: https://github.com/PHPOffice/PHPWord/issues/532

Basically i changed the function saveAs from:

rename($tempFilename, $strFilename);

to:

copy($tempFilename, $strFilename);
unlink($tempFileName);

and it now works a dream. Thanks again @John Smith for the help.

Ben Rhys-Lewis
  • 3,118
  • 8
  • 34
  • 45