How to save mpdf generated file to a folder? How to save mpdf generated file to a folder? codeigniter codeigniter

How to save mpdf generated file to a folder?


Short answer is to put the full path where you plan to save the file. Like so...

$mpdf->WriteHTML($html);$mpdf->Output('/etc/home/JohnWayne/example/pdf/','F');


You can use write file helper for this

$this->load->helper('file');write_file('my_pdf_file.pdf',$generated_pdf);

File Helper

For this follow these simple steps. Follow BASEPATH instead of APPPATH

$path   =   BASEPATH . 'file/invoice';if(is_dir($path)){    $this->mpdf->Output(realpath($path).'arif.pdf','F'); }else{    echo 'error';}

EDITS :

Here is an alternative solution which you might likeGo to application/config/constants.php and add constant there

define('FILE_PATH' , $_SERVER['DOCUMENT_ROOT']."my_project/file/");

Then use it like this.

$this->mpdf->Output(FILE_PATH ."invoice/arif.pdf",'F');


I found the solution. This is very simple. As for as mPDF library is concerned, it does not parse the base_url(). Instead we have to work with $_SERVER['DOCUMENT_ROOT']; In my case i have done as; Open the config.php in Application/config folder and insert the following;

$config['file_path']=$_SERVER['DOCUMENT_ROOT']."my_project/file/";

Now it is a peace of cake to call the config; Here is I have done in the controller;

$this->mpdf->Output($this->config->item('file_path')."invoice/arif.pdf",'F');

The Problem is solved. Do let me know if there is any technical or logical issue with my code.