如何提示保存pdf而不是用fpdf打开它
how to prompt to save pdf rather than opening it with 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");
}
?>
FPDF 的 output() 方法采用两个参数来确定如何输出文档。在我拥有的 FPDF 版本中,它们与 the documentation 相反,因此您可能想尝试两者:
$pdf->Output("filename.pdf", "D");
(对我有用)和:
$pdf->Output("D", "filename.pdf");
(根据文档)。
"D" 表示 "send to the browser and force a file download with the name given by name" 而默认值是 "I" 表示 "send the file inline to the browser. The PDF viewer is used if available."
我有 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");
}
?>
FPDF 的 output() 方法采用两个参数来确定如何输出文档。在我拥有的 FPDF 版本中,它们与 the documentation 相反,因此您可能想尝试两者:
$pdf->Output("filename.pdf", "D");
(对我有用)和:
$pdf->Output("D", "filename.pdf");
(根据文档)。
"D" 表示 "send to the browser and force a file download with the name given by name" 而默认值是 "I" 表示 "send the file inline to the browser. The PDF viewer is used if available."