0

我正在使用 LiveDocx 和 zend 框架从带有值的模板生成 word 文档。这就是我在控制器中所做的:

public function createwordAction(){
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender();

    require_once 'Zend/Service/LiveDocx/MailMerge.php';

    try{
        $filename = APPLICATION_PATH . "/../public/license-agreement-template.docx";

        chmod($filename,0777);

        $mailMerge = new Zend_Service_LiveDocx_MailMerge();

        $mailMerge->setUsername('******')
                  ->setPassword('*******');

        $mailMerge->setLocalTemplate($filename);

        $mailMerge->assign('software', 'Magic Graphical Compression Suite v1.9')
        ->assign('licensee', 'Henry Döner-Meyer')
        ->assign('company',  'Co-Operation')
        ->assign('date',     'January 11, 2010')
        ->assign('time',     'January 11, 2010')
        ->assign('city',     'Berlin')
        ->assign('country',  'Germany');

        $mailMerge->createDocument();

        $document = $mailMerge->retrieveDocument('docx');

        file_put_contents('document.docx', $document);
    }
    catch (Exception $e) {
        die ('Application error: ' . $e->getMessage());
    }
}

但我总是得到错误:

警告:file_put_contents(document.docx):无法打开流:第 313 行 /var/www/site/application/controllers/ResultsController.php 中的权限被拒绝

如您所见,我尝试使用 chmod 更改文件权限,但这并没有成功...

我还尝试像这样更改公用文件夹的权限:

$path = APPLICATION_PATH . "/../public";
chmod($path,0777);

但是给出了相同的结果..

4

2 回答 2

0

尝试更改目录文件mod,例如,

 $dir=APPLICATION_PATH . "/../public/";
 $filename = $dir."license-agreement-template.docx";
 chmod($dir,0777);
 chmod($filename,0777);

此外,您要放置内容的文件的名称应该是这样的$filename

file_put_contents($filename, $document);

代替_

file_put_contents('document.docx', $document);
于 2013-09-17T04:50:40.057 回答
0

你应该试试chmod 777

chmod($filename,0777);
于 2013-09-16T13:09:15.490 回答