将生成的pdf直接保存到文件夹文件夹 - Codeigniter

时间:2013-05-21 06:26:38

标签: php codeigniter codeigniter-2 dompdf

我想生成并将创建的pdf发送到文件夹,但是我收到错误,这个错误:

A PHP Error was encountered

Severity: Warning

Message: file_put_contents(http://localhost/NQCL1/workbooks/NDQA000000001/NDQA000000001.pdf) [function.file-put-contents]: failed to open stream: HTTP wrapper does not support writeable connections

Filename: libraries/Dompdf_lib.php

Line Number: 13

Dompdf_lib.php //库文件

class Dompdf_lib extends Dompdf{

        function createPDF($html, $filename='', $stream=TRUE){  
            $this->load_html($html);
            $this->render();
            $this->set_paper('a4', 'potratit');
            if ($stream) {
                //$this->stream($filename.".pdf"); - This works just ok
                file_put_contents(base_url().'workbooks/s'.$filename.'/'.$filename.".pdf", $this->output()); 

            } else {
                return $this->output();
            }
        }

}

coa.php // controller

function generateCoaDraft($labref,$offset=0) {
    // error_reporting(1);
    $data['labref'] = $labref = $this->uri->segment(3);
    $data['information'] = $this->getRequestInformation($labref);
    $data['tests_requested'] = $this->getRequestedTests($labref);
    $data['trd'] = $this->getRequestedTestsDisplay2($labref);
    $data['compedia_specification'] = $this->getCOABody($labref);
   $html = $this->load->view('coa_v', $data, true);
   $this->dompdf_lib->createPDF($html, $labref);
}

如果我使用它而不是file_put ....这行可以正常工作,如果我说STREAM = FALSE,它会返回空白页

$this->stream($filename.".pdf"); 

2 个答案:

答案 0 :(得分:2)

file_put_contents是本机PHP函数,因此将行更改为;

file_put_contents('workbooks/s'.$filename.'/'.$filename.".pdf", $this->output());

预先加上$ this->系统正在尝试查找属于该类的函数(该函数不存在),因此错误。

答案 1 :(得分:0)

我已经意识到我正在尝试通过HTTP与服务器通信,我只使用直接路径修改了代码并且它有效,谢谢guyz

这样:

file_put_contents(base_url().'workbooks/s'.$filename.'/'.$filename.".pdf", $this->output());

到此:

file_put_contents('workbooks/s'.$filename.'/'.$filename.".pdf", $this->output());