Cannot Save File to directory using FPDF

2019-04-11 15:43发布

问题:

I won't break out or show the lengthy code in actually building the PDF itself because I know the file generation is working fine.

When I try the following:

$pdf->Output('abc.pdf', 'F');

I receive error:

FPDF error: Unable to create output file: abc.pdf

By changing the Output destination to 'D' or 'I':

$pdf->Output('abc.pdf', 'D');

The user is prompted to download the pdf that was generated and is done so successfully (views fine). The error makes me think it is a permissions error but fpdf should have access to write a pdf file to the directory the action is already occurring in correct?

Anybody dealt with this before?

回答1:

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.



回答2:

chmod o+w your_directory fixed it for me :)



标签: php fpdf