我可以使用mpdf创建pdf文件。现在我想将生成的文件下载到用户系统,就像IDM下载器一样。但我无法这样做。
我试过像D,I,F这样的mpdf选项。只有F正在工作,但它将文件保存到服务器,这不是我的要求。
我也试过现在在代码中注释但它也没有用。
header('Content-type: application/force-download');
header('Content-Disposition: attachment; filename=mpdf.pdf');
readfile('mpdf.pdf');
这是代码
<?php
//db connection
$id = $_REQUEST['id'];
if($_REQUEST['action'] == "print") {
mysql_query('SET character_set_results = utf8');
$result = mysql_query("SELECT question_id FROM *** WHERE exam_id = '$id' ");
$exam_details = mysql_fetch_assoc(mysql_query("SELECT name, duration, passing_percent, negative_marking FROM *** WHERE id = '$id' "));
$num = mysql_num_rows($result);
while($row = mysql_fetch_assoc($result))
{
$results[] = $row['question_id'];
$question_id = $row['question_id'];
$result1 = mysql_query("SELECT question, option1, option2, option3, option4 FROM *** WHERE id = '$question_id' ");
while($row1 = mysql_fetch_assoc($result1))
{
$results1[] = $row1;
}
}
}
for($i=1; $i<=count($results1); $i++) {
$question = $i.'. '.$results1[$i-1]['question'];
$question = str_replace(array("\\","[","]"),"",$question);
$question = str_replace("(","<br> (",$question);
$option1 = $results1[$i-1]['option1'];
$option1 = str_replace(array("\\","[","]"),"",$option1);
$option2 = $results1[$i-1]['option2'];
$option2 = str_replace(array("\\","[","]"),"",$option2);
$option3 = $results1[$i-1]['option3'];
$option3 = str_replace(array("\\","[","]"),"",$option3);
$option4 = $results1[$i-1]['option4'];
$option4 = str_replace(array("\\","[","]"),"",$option4);
$html .= '<p style="font-size: 12pt; font-family: freeserif "><div style="float: left; width: 100%; margin-bottom:5px; font-family: freeserif">'.$question.'</div>';
}
include("../mpdf.php");
$mpdf=new mPDF('');
$html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
$mpdf->SetWatermarkImage('logo.jpg');
$mpdf->showWatermarkImage = true;
$mpdf->WriteHTML($html);
$mpdf->Output('mpdf.pdf');
//header('Content-type: application/force-download');
//header('Content-Disposition: attachment; filename=mpdf.pdf');
//readfile('mpdf.pdf');
?>
所以,请告诉我如何将生成的PDF保存到用户的系统中。