【发布时间】:2013-01-24 20:52:07
【问题描述】:
我正在尝试使用 dompdf 将表单保存到易于阅读的 .pdf 文件中,我的处理脚本如下。我收到错误Warning: file_put_contents(/files/grantapps/NAME0.pdf) [function.file-put-contents]: failed to open stream: No such file or directory in /home/username/public_html/subdir/apps/dompdf/filename.php on line 39。 (第 39 行是我完整脚本的最后一行。)我不知道如何解决这个问题。
allow_url_fopen 已打开,我尝试了各种文件路径,包括完整目录 (/home/username/public_html/subdir/files/grantapps/) 和下面代码中的内容,但没有任何效果。
require_once("dompdf_config.inc.php");
date_default_timezone_set('America/Detroit');
$html = 'code and whatnot is here';
$name = str_replace(" ", "", $_POST['form2name']);
$i = 0;
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
while(file_exists("files/grantapps/" . $name . $i . ".pdf")) {
$i++;
}
file_put_contents("files/grantapps/" . $name . $i . ".pdf", $dompdf->output());
【问题讨论】:
-
一个用户可以多次提交表单,并且由于我使用他们的名字作为文件名,我希望它只是在末尾附加一个数字并将每个文件保存为一个新文件命名而不是覆盖现有文件。
-
为什么不使用 $dompdf->stream("files/grantapps/" . $name . $i . ".pdf");
-
stream()函数会导致下载文件,并且只接受文件名作为参数。我想将文件保存在网络服务器上,其他位置说file_put_contents()是这样做的。 -
对于任何有相同错误消息并来到此线程的人,在我的情况下,问题是由于无效文件名(它包含
/)跨度>