dongsi0625
2016-02-11 15:05
浏览 270
已采纳

PHPWord - 无法打开已保存的文件,因为没有“访问权限”

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?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doudilin1225 2016-02-11 16:19
    已采纳

    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.

    已采纳该答案
    打赏 评论
  • doupinyan0186 2016-02-11 15:49

    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); 
    
    打赏 评论

相关推荐 更多相似问题