通过代码创建FPDF并通过方法调用
Create FPDF by code and call it by method
在我的项目中,我使用 fpdf
根据数据库中的数据生成 PDF 文件。
但是我想通过调用一些创建和保存文件的方法来预生成pdf。
save_data.php
($myPDF->createPDF($id)){
echo 'File was created';
}else{
echo 'There was a problem creating the file';
}
createPDF.php
//Code that generate the PDF using FPDF and at end save the file to server
$pdf->Output('/var/www/html/my_dir/my_pdf.pdf','F');
所以基本上我想将 createPDF.php 放在一个方法中,然后 return true
或 false
如果是否创建了 pdf。
编辑:
只是为了澄清。如果我能从 Output()
那里得到回复,那就容易多了。
我应该继续检查文件是否存在吗?
如果您只是想知道文件是否成功存盘:
function createPdf($pdf, $filename) {
// remove file if it already exists
if(file_exists($filename)) unlink($filename);
// save pdf
$pdf->output($filename, 'F');
// return true if successfull, false otherwise
return file_exists($filename);
}
在我的项目中,我使用 fpdf
根据数据库中的数据生成 PDF 文件。
但是我想通过调用一些创建和保存文件的方法来预生成pdf。
save_data.php
($myPDF->createPDF($id)){
echo 'File was created';
}else{
echo 'There was a problem creating the file';
}
createPDF.php
//Code that generate the PDF using FPDF and at end save the file to server
$pdf->Output('/var/www/html/my_dir/my_pdf.pdf','F');
所以基本上我想将 createPDF.php 放在一个方法中,然后 return true
或 false
如果是否创建了 pdf。
编辑:
只是为了澄清。如果我能从 Output()
那里得到回复,那就容易多了。
我应该继续检查文件是否存在吗?
如果您只是想知道文件是否成功存盘:
function createPdf($pdf, $filename) {
// remove file if it already exists
if(file_exists($filename)) unlink($filename);
// save pdf
$pdf->output($filename, 'F');
// return true if successfull, false otherwise
return file_exists($filename);
}