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


Saving generated pdf directly to a folder folder - Codeigniter

我想生成并发送创建的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//控制器
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"); 

file_put_contents是一个本地PHP函数,因此将该行改为;

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

通过在它前面加上$this->,系统试图找到一个属于这个类的函数(这个类不存在),因此出现错误。

我已经意识到我正试图通过HTTP与服务器通信,我修改了直接路径的代码,它工作了,谢谢大家

:

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

:

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