我遇到了 HTML2PDF 库的问题(我将 PHP 与 Zend Framework 2 结合使用)。
我在 linux ubuntu 专用服务器上,我的 .pdf 文件的目标文件夹有 chmod 777。我什至尝试过 chmod 666 ...但我仍然遇到同样的错误:
[warn] [client ..*.*] mod_fcgid: stderr: PHP Warning: fopen(/my_absolute_path/file.pdf): failed to open stream: Permission denied in /my_absolute_path/html2pdf/_tcpdf_5.0.002/tcpdf.php on line 6168
有答案吗? 非常感谢
编辑
@Novocaine88,你是对的:-)
这是我非常简单的代码:
// Set the file path
$path = ROOT_PATH.'/data/myFolder_chmod_777/file.pdf';
// Create the pdf document
require_once ROOT_PATH . '/vendor/html2pdf/html2pdf.class.php';
$pdf = new \HTML2PDF('P', 'A4', 'fr');
// Get the content
$content = $this->getHtmlContent($required_param);
// Forge PDF doc
$pdf->WriteHTML($content);
// Save doc
$pdf->Output($path, 'F');
这是(大约)我从 HTML2PDF 的官方网站 (http://html2pdf.fr/example) 获得的代码。 当我在本地机器上使用它时,一切正常,但在远程服务器上......
解决方案
在阅读我的代码一百遍之后,我发现了问题所在。 这很愚蠢,我没有正确设置路径。
代码如下:
// Set the file path
$path = ROOT_PATH.'/data/folder/myFolder_chmod_777/file.pdf';
现在可以了!
请您参考如下方法:
顺便说一句,您可以省略 ROOT_PATH 常量。
查看 ZF2 的 public/index.php 文件。
/**
* This makes our life easier when dealing with paths. Everything is relative
* to the application root now.
*/
chdir(dirname(__DIR__));
所以你的代码也应该适用于
// Set the file path
$path = '/data/folder/myFolder_chmod_777/file.pdf';
