如何提示保存pdf而不是用fpdf打开它

时间:2016-02-27 08:34:18

标签: php html fpdf

我有php代码将表单中的数据保存为pdf。但是现在,它只是以pdf打开数据而不是提示我将其保存为pdf。我怎样才能做到这一点? 我的代码如下:

<?php
if(!empty($_POST['submit']))
{

$f_name=$_POST['first_name'];
$l_name=$_POST['last_name'];
$gender=$_POST['gender'];
$dob=$_POST['dob'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];

require("fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();

$pdf->SetFont("Arial","B",16);
$pdf->Cell(10,10,"welcome {$f_name}",1,0);
$pdf->Cell(50,10,"Name :",1,0);
$pdf->Cell(50,10,"$l_name",1,0);

$pdf->Cell(50,10,"gender :",1,0);
$pdf->Cell(50,10,"$gender",1,1);

$pdf->Cell(50,10,"Mobile :",1,0);
$pdf->Cell(50,10,"$mobile",1,1);

$pdf->Cell(50,10,"Email :",1,0);
$pdf->Cell(50,10,"$email",1,1);


$pdf->Output("D", "filename.pdf");

}

?>

1 个答案:

答案 0 :(得分:1)

FPDF的output()方法有两个参数,用于确定如何输出文档。在我所拥有的FPDF版本中,它们与the documentation的方式相反,所以你可能想要尝试两者:

$pdf->Output("filename.pdf", "D");

(对我有用)和:

$pdf->Output("D", "filename.pdf");

(根据文件)。

“D”表示“发送到浏览器并强制使用名称给出的名称下载文件”,而默认值为“I”,表示“将文件内联发送到浏览器。如果可用,则使用PDF查看器。 “

相关问题