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

查看:125
本文介绍了无法使用FPDF将文件保存到目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我知道文件生成工作正常,因此在实际构建PDF本身时,我不会详细介绍或显示冗长的代码.

当我尝试以下操作时:

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

我收到错误:

FPDF错误:无法创建输出 档案:abc.pdf

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

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

提示用户下载已生成并成功完成的pdf(查看效果良好).该错误使我认为这是一个权限错误,但是fpdf应该有权将pdf文件写入该操作已经正确执行的目录吗?

有人处理过吗?

解决方案

如果您的PHP脚本是从网页(由Apache提供)中执行的,则将执行此代码由Apache (有时称为www-data)用户.

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


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

chmod o+w your_directory


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

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.

这篇关于无法使用FPDF将文件保存到目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆