HTML2PDF - fopen() failed to open stream: Permission denied in/html2pdf/_tcpdf_5.0.002/tcpdf.php on line 6168

3.8k views Asked by At

I got a problem with the HTML2PDF library (i use PHP with 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 :

[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

Any answers ? Thx much

EDIT

@Novocaine88, you're right :-)

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 ...

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

There are 1 answers

0
Markus Schindler On

BTW you can ommit the ROOT_PATH constant.

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

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