Search code examples
phppdffpdf

Output file to server directory in FPDF


I'm using PHP to put together a PDF using FPDF, right at the bottom I have this:

$pdf->Output("../uploads/filename.pdf",'F');
header("location:../uploads/filename.pdf");

The top line should save the PDF to the uploads folder in the root, and the bottom should show it in the browser. I get this message:

FPDF error: Unable to create output file: ../uploads/filename.pdf

I've even tried making the file path using a variable as suggested in other posts on this site but I still get the same error. I have 777 permissions set throughout the uploads folder too. Thanks.


Solution

  • I've actually figured it out, it's a weird fix but it works.

    $path = "../../../../uploads/AAA.pdf";
    $pdf->Output($path,'F');
    header('location:'.$path);
    

    I had to keep jumping back to the root, then go into the /uploads/ folder specifically. Thanks for the answers so far.