我正在使用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);
但同样的结果......
答案 0 :(得分:0)
您应该尝试 chmod 777
chmod($filename,0777);
答案 1 :(得分: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);