【问题标题】:PDF created with FPDF and how to save and retrieve the pdf [closed]使用 FPDF 创建的 PDF 以及如何保存和检索 pdf [关闭]
【发布时间】:2012-02-24 20:43:51
【问题描述】:

如何将 FPDF 创建的 PDF 存储在 MySQL 数据库中?

【问题讨论】:

  • 请在此处阅读有关如何提问的常见问题解答。 faqHow to Ask

标签: php mysql fpdf


【解决方案1】:

您确定确实需要将生成的 PDF 保存到数据库吗?也许您可以将 PDF 保存到文件系统,并将文件的路径保存在数据库中。

【讨论】:

    【解决方案2】:

    在您的数据库中:

    • 将 cloumn 类型设置为 BLOB

    保存:

    //make a pdf
    $pdf=new FPDF();
    $pdf->AddPage();
    
    //set pdf to savable type
    $pdfcontent = $pdf->Output("", "S");
    
    //save pdf to database
    $mysqli=new mysqli("hostname", "username", "password", "database");
    $stmt = $mysqli->prepare("INSERT INTO pdfs (pdf) VALUES (?)");
    $stmt->bind_param('s', $pdfcontent);
    $stmt->execute();
    

    检索:

    $mysqli=new mysqli("hostname", "username", "password", "database");
    $stmt = $mysqli->prepare("SELECT pdf FROM pdfs WHERE id = ?");
    $stmt->bind_param('i',$id);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($pdfcontent);
    while($stmt->fetch()){
        header("Content-Length: " . strlen($pdfcontent) );
        header("Content-Type: application/octet-stream");
        header('Content-Disposition: attachment; filename="WarriorDeals_Voucher_'.$number.'-'.$numIndex.'.pdf"');
        header("Content-Transfer-Encoding: binary\n");
        echo $pdfcontent;
    }
    

    【讨论】:

    • hai Dan Kanze 我不清楚这行值---->> $stmt = $mysqli->prepare("INSERT INTO pdfs (pdf) VALUES (?)");
    【解决方案3】:

    我不确定我是否理解您的问题,但万一这就是我认为您要问的... 您将需要根路径以及用于存储文件的文件名,以创建正确的数据库条目。您必须使用 mysql 数据库和插入查询来输入它,只要选择查询来检索其位置并在您的网站中使用它。 在 w3schools 阅读 PHP/mySQL 的基础知识并考虑 FPDF,阅读上传的常见问题解答here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-04
      • 1970-01-01
      • 2013-11-12
      • 1970-01-01
      • 1970-01-01
      • 2012-10-23
      • 1970-01-01
      相关资源
      最近更新 更多