dongzha0149 2013-12-05 13:38
浏览 89

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

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条回答 默认 最新

  • douyi7055 2013-12-06 21:25
    关注

    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';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型