php - file_put_contents : Failed to open stream, 没有那个文件或目录

标签 php dompdf

我正在尝试使用 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 第 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());

最佳答案

目标文件夹路径肯定有问题。

您上面的错误消息说,它想将内容放入目录 /files/grantapps/ 中的文件,这将超出您的 vhost,但在某处在系统中(查看前导绝对斜线)

你应该仔细检查:

  • 目录 /home/username/public_html/files/grantapps/ 是否真的存在。
  • 包含你的循环和你的 file_put_contents-Statement 的绝对路径 /home/username/public_html/files/grantapps/

关于php - file_put_contents : Failed to open stream, 没有那个文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14783592/

相关文章:

php - 使用 codeigniter 通过电子邮件发送 dompdf 生成的 pdf

php - dompdf制作页眉和页脚 "solid"

css - dompdf 内部分页 : avoid on table not working

php - Cpdf.php 行 3855 : Undefined index: at barryvdh/laravel-dompdf 中的 ErrorException

php - 在新标签页中打开 dompdf 从给定页面获取数据

php - 覆盖组件/com_users/models/forms/login.xml 添加类 - Joomla 3

php - 跨域 ajax 和 php session

PHP 动态表数据结果垂直而不是水平

php - 如果模块位置有模块,如何将类名添加到 body 标签?

php - 我可以在我的网站上提供网站审核工具吗?