Search code examples
phppdffpdf

FPDF - output dynamic file name


I'm creating a PDF page from an html form, so my php looks like this (for example):

$pdf->Cell(0,0,$_POST['teacher_name'],0,2,'C');

What is my missing step that I can define that variable (teacher_name) to create my output file as:

$pdf->Output('homework-teacher_name.pdf', 'D');

and the teacher_name in the output is replaced by whatever is submitted in the form?


Solution

  • $fileName = 'homework-' . $_POST['teacher_name'] . '.pdf';
    $pdf->Output($fileName, 'D');
    

    Remember to sanitize external inputs using filter_input