gpt4 book ai didi

php - 使用 FPDF 将文件保存到预先指定的目录

转载 作者:IT王子 更新时间:2023-10-29 00:20:33 26 4
gpt4 key购买 nike

我想将 PDF 文件保存到用户指定的目录中。我正在使用 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');

我已检查我尝试写入的目录是否具有写入/读取权限并且它就在那里。它仍然不起作用!

请帮助某人...

最佳答案

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

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

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

关于php - 使用 FPDF 将文件保存到预先指定的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4339787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com