1

我想生成创建的 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"); 
4

2 回答 2

2

file_put_contents是原生 PHP 函数,因此将行更改为;

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

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

于 2013-05-21T06:37:43.367 回答
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());
于 2013-05-21T07:02:00.137 回答