When running code the file is the pdf file is getting saved in the browser instead of it getting saved on the server
fpdf Output('filename.pdf','F');
downloading file on browser instead of saving it on the server
When running code the file is the pdf file is getting saved in the browser instead of it getting saved on the server
fpdf Output('filename.pdf','F');
downloading file on browser instead of saving it on the server
As explained in the FPDF documentation, you have to use the D
as parameter to the output
function to send the PDF to the browser and force a file download with the name given by name:
Output('D','filename.pdf');
For reference, here are the different values for the destination
parameter:
I: send the file inline to the browser. The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
D: send to the browser and force a file download with the name given by name.
F: save to a local file with the name given by name (may include a path).
S: return the document as a string. name is ignored.
Here is the example, checkit out!
$pdf->Output(F,'directory/filename.pdf');
Remember that if you use F in the output settings that your directory on your server needs to have permissions set to 777 or it does not work. Hope that helps anyone who is not getting the file to save to their directory.
:) Kim
I'm using FPDF 1.6 and PHP 7.0.33 and the Output() function does not work like the manual says.
I couldn't find the manual for this version, and the manual for the version 1.81 says to use this function like this:
string Output([string dest [, string name [, boolean isUTF8]]])
But, in my project it only works with the following parameter order:
string Output( string name,string dest, boolean isUTF8)
Output
string Output([string dest [, string name [, boolean isUTF8]]])
Description
Send the document to a given destination: browser, file or string. In the case of a browser, the PDF viewer may be used or a download may be forced.
The method first calls Close() if necessary to terminate the document.
Parameters
Example:
$pdf->Output('D', "filename.pdf", true);
This worked for me. $PaymentReference
is a string.
$pdf->Output('',$PaymentReference.'.pdf', false);
Late to the party, but for helping others who may be looking for similar solutions. Using the documentation, this is what worked for me
if (!class_exists('FPDF'))
require(plugin_dir_path( __FILE__ ).'pdf/fpdf.php');
$pdf = new FPDF('P', 'in', 'Letter');
$pdf->AddPage();
$pdf->SetFont("Arial","B",14);
$pdf->Cell(50,50, "this is a pdf example 1", 0, 1, 'C', true);
// Now download to the local computer
$pdf->Output("test.pdf", "D"); // Download to the user's computer
or to put to the same browser page
if (!class_exists('FPDF'))
require(plugin_dir_path( __FILE__ ).'pdf/fpdf.php');
$pdf = new FPDF('P', 'in', 'Letter');
$pdf->AddPage();
$pdf->SetFont("Arial","B",14);
$pdf->Cell(50,50, "this is a pdf example 1", 0, 1, 'C', true);
ob_clean(); // CLEAN THE previous output for the page.
$pdf->Output("test.pdf", "I"); // display pdf in the same page