无法使用FPDF将文件保存到目录中[英] Cannot Save File to directory using FPDF

本文是小编为大家收集整理的关于无法使用FPDF将文件保存到目录中的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我不会突破或显示冗长的代码在实际构建PDF本身时,因为我知道文件生成正常.

当我尝试以下操作时:

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

我收到错误:

FPDF错误:无法创建输出 文件:abc.pdf

通过将输出目标更改为" D"或" I":

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

提示用户下载生成并成功完成的PDF(视图罚款).错误使我认为这是一个权限错误,但是FPDF应该可以访问将PDF文件写入目录,该操作已经在正确的?

中发生?

有人在处理这个问题吗?

推荐答案

如果您的PHP脚本是从Web Page 执行的(Apache提供的,它是),则此代码将由Apache 执行(有时称为)用户.

因此,您的Apache用户需要能够写入您要写入的目录.


通常,您可能必须将write特权授予系统的other用户,并使用命令行中的类似内容:

chmod o+w your_directory


您正在使用的软件上传源文件(如果使用GUI)应该允许您使用几个Chekbox进行此操作 - 您需要检查"其他"用户的"写"复选框.

其他推荐答案

chmod o+w your_directory为我修复了它:)

本文地址:https://www.itbaoku.cn/post/2090899.html

问题描述

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?

推荐答案

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.

其他推荐答案

chmod o+w your_directory fixed it for me :)

相关标签/搜索