用FPDF创建的PDF以及如何保存和检索pdf [英] PDF created with FPDF and how to save and retrieve the pdf
本文介绍了用FPDF创建的PDF以及如何保存和检索pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将FPDF创建的PDF存储在MySQL数据库中?
How do I store a PDF created by FPDF in a MySQL database?
推荐答案
在您的数据库中:
- 将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;
}
这篇关于用FPDF创建的PDF以及如何保存和检索pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文