Php 将生成的pdf直接保存到文件夹-Codeigniter
我想生成已创建的pdf并将其发送到文件夹,但出现错误,此错误:Php 将生成的pdf直接保存到文件夹-Codeigniter,php,codeigniter,codeigniter-2,dompdf,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 su
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");
是本机PHP函数,因此将行更改为
file_put_contents('workbooks/s'.$filename.'/'.$filename.".pdf", $this->output());
通过在它前面加上$this->系统试图找到属于该类的函数(该类不存在),因此出现了错误。我意识到我试图通过HTTP与服务器通信,我修改了代码,只使用了直接路径,它成功了,谢谢guyz 这: 为此:
file_put_contents('workbooks/s'.$filename.'/'.$filename.".pdf", $this->output());
只需在命令写入文件之前删除$this->。file_put_contents()是一个本机PHP函数。我删除了$this,现在又删除了一个新的连接错误。该错误是由于在文件路径中使用了http,而在路径中使用了base_url()。结帐非常感谢鲁尼,我现在弄对了
file_put_contents('workbooks/s'.$filename.'/'.$filename.".pdf", $this->output());