Saving file into a prespecified directory using FP

2019-03-18 09:03发布

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...

标签: php pdf fpdf
8条回答
手持菜刀,她持情操
2楼-- · 2019-03-18 09:27

Having struggled with this myself, there are three things one has to ensure, two of which are mentioned in other posts on this topic:

  1. Command: output('F', "xyz_file");
  2. Permissions on the server's destination directory need to allow writes for non-escalated privileges (i.e. drwxrwxrwx)
  3. Definition of content type: header("Content-type:application/pdf");
查看更多
聊天终结者
3楼-- · 2019-03-18 09:33

Have you tried file upload? I think you and I might be trying to do the same thing and this seems to work. I am working on a shared drive as well.

http://php.net/manual/en/features.file-upload.post-method.php

查看更多
登录 后发表回答