使用mPDF库创建PDF。文件已创建,我尝试创建不同的PDF文件,但它创建了我需要的文件数,但所有文件都包含第一个文件的相同数据。这是我的问题的示例代码
控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller{
public function page1(){
$this->load->view('view_upload');
}
public function page2(){
$file = fopen($_FILES['file']['tmp_name'], 'r+');
$i=0;
$user['data']=fgetcsv($file);
echo "<br><br>";
//print_r($user);
//load the view and saved it into $html variable
$html=$this->load->view('print_1', $user, true);
//this the the PDF filename that user will get to download
$pdfFilePath = $i.".pdf";
//load mPDF library
$this->load->library('m_pdf');
//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);
//download it.
$this->m_pdf->pdf->Output("output/".$pdfFilePath, 'F');
++$i;
$html=$this->load->view('print', $user, true);
//this the the PDF filename that user will get to download
$pdfFilePath = $i.".pdf";
//load mPDF library
$this->load->library('m_pdf');
//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);
//download it.
$this->m_pdf->pdf->Output("output/".$pdfFilePath, 'F');
fclose($file);
}
}
视图:
print_1
<?php
echo "print_1";
?>
打印
<?php
echo "print";
?>
它创建了两个PDF文件,都有“ print_1 ”数据。 备注:没有使用变量$ user,它在我的实际代码中使用
答案 0 :(得分:0)
尝试这个(它真的那么明显吗?)
print.php中的
foreach($data AS $key => $arrData)
{
echo implode(",",$arrData);
echo "<br />";
}