0

I'm working with LiveDocx and zend framework to generate a word document from a template with values. This is what I do in my controller:

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());
    }
}

But I always get the error:

Warning: file_put_contents(document.docx): failed to open stream: Permission denied in /var/www/site/application/controllers/ResultsController.php on line 313

As you can see I tried to change the file permissions with chmod but that didn't do the trick ...

I also tried to change permissions of public folder like this:

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

But same result was given ..

nielsv
  • 6,540
  • 35
  • 111
  • 215

2 Answers2

0

You should try chmod 777

chmod($filename,0777);
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
0

Try to change mod of directory and file both like,

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

Also the name of file in which you want to put the contents should be the $filename like

file_put_contents($filename, $document);

In place of

file_put_contents('document.docx', $document);
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106