dsfjk44656 2016-02-27 08:34
浏览 84
已采纳

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

I have php code that saves the data in a form to pdf. However right now, its simply opening the data in pdf rather than prompting me to save it as pdf. How can I do that? My code is as follows:

<?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条回答 默认 最新

  • dongzha0813 2016-02-27 08:47
    关注

    FPDF's output() method takes two parameters which determine how to output the document. In the version of FPDF I have, they are the opposite way around to the documentation, so you might want to try both:

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

    (which worked for me) and:

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

    (which is as per the documentation).

    "D" means "send to the browser and force a file download with the name given by name" whereas the default is "I" which means "send the file inline to the browser. The PDF viewer is used if available."

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么