HTML2PDF - fopen()无法打开流:6168行/ html2pdf / _tcpdf_5.0.002 / tcpdf.php中的权限被拒绝

时间:2022-10-09 15:22:31

I got a problem with the HTML2PDF library (i use PHP with Zend Framework 2).

我遇到了HTML2PDF库的问题(我使用PHP和Zend Framework 2)。

I'm on a linux ubuntu dedicated server and the destination folder for my .pdf file got chmod 777. I even tried chmod 666 ... but i still get the same error :

我在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

[warn] [client .. *。*] mod_fcgid:stderr:PHP警告:fopen(/my_absolute_path/file.pdf):无法打开流:/my_absolute_path/html2pdf/_tcpdf_5.0.002/tcpdf.php上的权限被拒绝6168

Any answers ? Thx much

任何答案?太多了

EDIT

编辑

@Novocaine88, you're right :-)

@ Novocaine88,你是对的:-)

Here is my very simple code :

这是我非常简单的代码:

// 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');

This is (approximately) the code i get from the official site of HTML2PDF (http://html2pdf.fr/example). When i use it on my local machine, everything works fine, but on the distant server ...

这是(大约)我从HTML2PDF官方网站获得的代码(http://html2pdf.fr/example)。当我在我的本地机器上使用它时,一切正常,但在遥远的服务器上......

SOLUTION

After reading my code a hundred times, i found the problem. This is stupid, i didn't set the path correctly.

在阅读了我的代码一百次后,我发现了问题。这是愚蠢的,我没有正确设置路径。

Here is the code :

这是代码:

// Set the file path
$path = ROOT_PATH.'/data/folder/myFolder_chmod_777/file.pdf';

It works now !

它现在有效!

1 个解决方案

#1


1  

BTW you can ommit the ROOT_PATH constant.

顺便说一句,你可以省略ROOT_PATH常量。

Look into your ZF2's public/index.php file.

查看您的ZF2的public / index.php文件。

/**
 * This makes our life easier when dealing with paths. Everything is relative
 * to the application root now.
 */
chdir(dirname(__DIR__));

So your code should also work with

所以你的代码也应该使用

// Set the file path
$path = '/data/folder/myFolder_chmod_777/file.pdf';

#1


1  

BTW you can ommit the ROOT_PATH constant.

顺便说一句,你可以省略ROOT_PATH常量。

Look into your ZF2's public/index.php file.

查看您的ZF2的public / index.php文件。

/**
 * This makes our life easier when dealing with paths. Everything is relative
 * to the application root now.
 */
chdir(dirname(__DIR__));

So your code should also work with

所以你的代码也应该使用

// Set the file path
$path = '/data/folder/myFolder_chmod_777/file.pdf';