使用FPDF将文件保存到预先指定的目录中
我想将PDF文件保存到用户指定的目录中.我正在使用FPDF.代码如下:
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');
?>
现在即使将"G:\PDF\"
放在文件名中也无法保存!我尝试了以下方法:
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!
请帮助某人...
您错误地使用了F选项,F旨在将PDF本地保存在服务器上,而不是保存在用户计算机上的特定目录中.所以你会用类似的东西:
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');
这将保存在您的网络服务器的public_html目录中
This will save in in the public_html directory of your webserver