Saving file into a prespecified directory using FPDF

Sharmin picture Sharmin · Dec 2, 2010 · Viewed 87.4k times · Source

I want to save the PDF file into a user specified directory. I am using FPDF. And the code is as below:

<?php
//echo "<meta http-equiv=\"refresh\" content=\"0;url=http://www.train2invest.net/useradmin/atest_Khan.php\">";
require('fpdf.php');

//create a FPDF object
$pdf=new FPDF();

//set font for the entire document
$pdf->SetFont('times','',12);
$pdf->SetTextColor(50,60,100);

//set up a page
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default');

//Set x and y position for the main text, reduce font size and write content
$pdf->SetXY (10,60);
$pdf->SetFontSize(12);
$pdf->Write(5,'Dear Ms.XYX');

 $filename="test.pdf";
//Output the document
$dir = "/G:/PDF/test.pdf/"; // full path like C:/xampp/htdocs/file/file/
$pdf->Output($dir.$filename,'F');
?>

Now even if I put "G:\PDF\" in the filename it doesn't save it!! I have tried the following:

$filename="G:\PDF\test.pdf";
$pdf->Output($filename.'.pdf','F');


$filename="G:\\PDF\\test.pdf";
$pdf->Output($filename.'.pdf','F');

$filename="G:/PDF/test.pdf";
$pdf->Output($filename.'.pdf','F');


$filename="/G:/PDF/test.pdf/";
$pdf->Output($filename.'.pdf','F');

I have checked that the directory i am trying to write has write/read permission and it's there. IT STILL DOESN'T WORK!

PLEASE help somebody...

Answer

user2559331 picture user2559331 · Jul 8, 2013

You are using the F option incorrectly, F is designed to save the PDF locally on the Server not in a specific directory on the users machine. So you would use something like:

$filename="/home/user/public_html/test.pdf";
$pdf->Output($filename,'F');

This will save in in the public_html directory of your webserver