Saving file into a prespecified directory using FPDF

大城市里の小女人 提交于 2019-12-03 06:00:55
user2559331

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

9finger

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");

Check the syntax here: http://www.fpdf.org/en/doc/output.htm It is: string Output([string dest [, string name [, boolean isUTF8]]]), so you have to write:

$pdf->Output('F', $filename, true); // save into the folder of the script

or e.g.:

$pdf->Output('F', '/var/www/html/wp-content/' . $filename, true); // save into some other location

or relative path:

$pdf->Output('F', '../../' . $filename, true); // to parent/parent folder

However, I am not sure if you can use windows absolute path...

Its because you are trying to save the file somewhere it doesnt want you to. Most probably because your havent set the permissions of the directory to 777.

If your PHP script is executed from a web-page (served by Apache, it is), then this code will be executed by the Apache (sometimes called www-data) user.

So, your Apache user needs to be able to write to the directory you're trying to write to.

Typically, you might have to give the write privilege to the other users of your system, using something like this from a command-line :

chmod o+w your_directory

The software you're using to upload your source files, if doing so using a GUI, should allow you to do that with a couple of chekboxes -- you need to check the "write" checkbox for the "others" users.

Likely permissions of your Apache service:

http://www.php.net/manual/en/function.opendir.php#87479

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

I solved like this:

public functon GeneratePdf(){
    ...
    PDF::Output("C:/xampp/htdocs/MyProject/doc.pdf","F"); 
}

I copied all directory path into Output method and I did not set further permissions for this.

I hope it helps you!!

change the 'F' to 'D'. D forces download. So your $pdf->output line should look like this.

$pdf->Output($path,'D');
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!