php 无法使用 FPDF 将文件保存到目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5736965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot Save File to directory using FPDF
提问by JM4
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.
我不会在实际构建 PDF 本身时打破或显示冗长的代码,因为我知道文件生成工作正常。
When I try the following:
当我尝试以下操作时:
$pdf->Output('abc.pdf', 'F');
I receive error:
我收到错误:
FPDF error: Unable to create output file: abc.pdf
FPDF 错误:无法创建输出文件:abc.pdf
By changing the Output destination to 'D' or 'I':
通过将输出目标更改为“D”或“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?
系统会提示用户下载生成的 pdf 并成功下载(查看效果很好)。该错误让我认为这是一个权限错误,但 fpdf 应该有权将 pdf 文件写入该操作已正确发生的目录?
Anybody dealt with this before?
以前有人处理过这个吗?
回答by Pascal MARTIN
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.
如果您的 PHP 脚本是从网页(由 Apache 提供服务)执行的,那么此代码将由 Apache (有时称为www-data
)用户执行。
So, your Apache user needs to be able to write to the directory you're trying to write to.
因此,您的 Apache 用户需要能够写入您尝试写入的目录。
Typically, you might have to give the write
privilege to the other
users of your system, using something like this from a command-line :
通常,您可能必须从命令行使用类似以下内容的方式将write
权限授予other
系统用户:
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.
您用来上传源文件的软件(如果使用 GUI 上传)应该允许您使用几个复选框来执行此操作——您需要为“其他”用户选中“写入”复选框。
回答by Robert Saylor
chmod o+w your_directory
fixed it for me :)
chmod o+w your_directory
为我修好了:)