2010-12-02 54 views
13

我想将PDF文件保存到用户指定的目录中。我正在使用FPDF。并且代码如下:使用FPDF将文件保存到预先指定的目录中

<?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\"的文件名不保存它!我试过以下内容:

$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'); 

我检查了我想写的目录有写入/读取权限,它在那里。它仍然行不通!

请帮助别人......

+0

使用格式化`代码块`它很难读取你的问题和`php`标签以获得正确的人的注意力 – Ish 2010-12-02 21:02:39

+0

你有没有尝试过将它输出到浏览器以查看`Output()`例程是否工作所有?将'F'切换到'D'来尝试。 – Orbling 2010-12-02 21:40:21

回答

1

它,因为你要保存文件的地方它不想要你。很可能是因为你没有将目录的权限设置为777.

如果你的PHP脚本是从一个web页面(由Apache提供的)执行的,那么这个代码将由Apache执行(有时称为www-data)用户。

因此,您的Apache用户需要能够写入您尝试写入的目录。

通常情况下,你可能得给写权限到系统的其他用户,使用这样的事情从一个命令行:

文件模式Ø+ W your_directory

该软件你使用上传你的源文件,如果使用GUI这样做,应该允许你用一些chekbox来做 - 你需要检查“其他”用户的“写”复选框。

29

您正在错误地使用F选项,F旨在将本地PDF保存在服务器上,而不是在用户计算机上的特定目录中。所以,你会使用类似:

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

这将保存在你的网络服务器的public_html目录

0

已经挣扎,这一点我自己,有三件事人们必须确保,其中两个在其他职位都提到这个话题:

  1. 命令:输出(“xyz_file” F);
  2. 服务器目标目录上的权限需要允许写入非升级权限(即,drwxrwxrwx)
  3. 内容类型的定义:header(“Content-type:application/pdf”);
相关问题