在文件夹中存储MPDF输出

时间:2017-11-23 06:30:03

标签: php codeigniter mpdf

我需要将我的PDF输出保存在CodeIgniter中的一个文件夹中,我该如何操作我在下面给出的控制器,现在我的MPdf输出正在下载,但我需要显示并将其保存到文件夹以供将来访问

我的控制器

class Pdf extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('M_pdf');
    }
    public function index() {
        //load view
        $this->load->model("crud_model");
        $data["fetch_data_seminar"] = $this->crud_model->fetch_data_seminar();
        $data1["fetch_data_conf"] = $this->crud_model->fetch_data_conf();
        $data2["fetch_data_extra"] = $this->crud_model->fetch_data_extra();
        $data3["fetch_data_cgpa"] = $this->crud_model->fetch_data_cgpa();
        $data4["fetch_data_representation"] = $this->crud_model->fetch_data_representation();
        $data5["fetch_data_participation"] = $this->crud_model->fetch_data_participation();
        $data6["fetch_data_organ"] = $this->crud_model->fetch_data_organ();
        $data7["fetch_data_events"] = $this->crud_model->fetch_data_events();
        $data8["fetch_data_program"] = $this->crud_model->fetch_data_program();
        $data_array = array(
            'seminar' => $data,
            'conf' => $data1,
            'extra' => $data2,
            'cgpa' => $data3,
            'representation' => $data4,
            'participation' => $data5,
            'organ' => $data6,
            'events' => $data7,
            'program' => $data8,
        );

        $showdata = [];
        $html = $this->load->view('makepdf', $data_array, TRUE);
        $pdfFilePath = "download.pdf";
        $this->m_pdf->pdf->WriteHTML($html);
        $this->m_pdf->pdf->Output(pdfFilePath . pdf, "D");
    }
    public function generatepdf() {

    }
}

1 个答案:

答案 0 :(得分:2)

$pdfFilePath = "download.pdf";

//save in folder
$this->m_pdf->pdf->Output("./your_folder_location/".$pdfFilePath, "F");

//download file
$this->m_pdf->pdf->Output($pdfFilePath, "D");