0

私は LiveDocx と zend フレームワークを使用して、値を持つテンプレートから単語文書を生成しています。これは私がコントローラーで行うことです:

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 に答える