file_put_contents:无法打开流,没有这样的文件或目录 [英] file_put_contents: Failed to open stream, no such file or directory

查看:652
本文介绍了file_put_contents:无法打开流,没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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行是我完整脚本的最后一行.)我不知道如何解决此问题.

I am trying to use dompdf to save a form to an easily-readable .pdf file, and my processing script is below. I am receiving the error 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. (Line 39 is the final line in my full script.) I don't know how to resolve this issue.

allow_url_fopen处于打开状态,我尝试了各种文件路径,包括完整目录(/home/username/public_html/subdir/files/grantapps/)以及下面的代码中的内容,但没有任何作用.

allow_url_fopen is on, and I have tried all kinds of file paths, including the full directory (/home/username/public_html/subdir/files/grantapps/) and what's in the code below, but nothing worked.

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());

推荐答案

目标文件夹路径确实存在问题.

There is definitly a problem with the destination folder path.

您的上述错误消息说,它希望将内容放入目录/files/grantapps/中的文件中,该文件可能不在您的vhost目录中,但在系统中的某个位置(请参见前导绝对斜杠)

Your above error message says, it wants to put the contents to a file in the directory /files/grantapps/, which would be beyond your vhost, but somewhere in the system (see the leading absolute slash )

您应该仔细检查:

  • 目录/home/username/public_html/files/grantapps/确实存在吗?
  • 包含循环,而file_put_contents-Statement包含绝对路径/home/username/public_html/files/grantapps/
  • Is the directory /home/username/public_html/files/grantapps/ really present.
  • Contains your loop and your file_put_contents-Statement the absolute path /home/username/public_html/files/grantapps/

这篇关于file_put_contents:无法打开流,没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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