alphy
alphy

Reputation: 991

Saving generated pdf directly to a folder folder - Codeigniter

I would like to generate and send the created pdf to a folder but i get an error, this error :

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 //library file

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);
}

This line works fine if i use it instead of file_put...., if i say STREAM=FALSE, it return blank page

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

Upvotes: 1

Views: 15819

Answers (2)

Rooneyl
Rooneyl

Reputation: 7902

file_put_contents is a native PHP function, so change the line to;

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

By prepending it with $this-> the system is trying to find a function that belongs to the class (which doesn't exist), hence the error.

Upvotes: 2

alphy
alphy

Reputation: 991

I have realized that i am trying to communicate with the server over HTTP, i modified the code with just the direct path and it worked, Thanks guyz

this:

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

to this:

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

Upvotes: 0

Related Questions