Saving file into a prespecified directory using FPDF

To save a file using FPDF, you can use the "Output" method. This method takes two parameters: the name of the file and the destination (where the file should be saved).

Watch a course Learn object oriented PHP

For example, to save a file named "mypdf.pdf" in the "downloads" directory, you can use the following code:

$pdf->Output('downloads/mypdf.pdf', 'F');

The second parameter, 'F', stands for "save to a local server file". If you want to send the file as a download to the client, you can use 'D' instead.

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

Please note that the Output method must be the last one to be called on your FPDF object, otherwise it will not work.