file_put_contents:无法打开流,没有这样的文件或目录

vai*_*dil 12 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 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());
Run Code Online (Sandbox Code Playgroud)

Som*_*now 35

目标文件夹路径肯定存在问题.

你上面的错误信息说,它想把内容放到目录中的一个文件中/files/grantapps/,这可能超出你的范围vhost,但在系统的某个地方(参见前面的绝对斜线)

你应该仔细检查:

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

  • 我是世界上最大的白痴.我做了所有事情*除了*创建`/ grantapps /`目录.创建并返回完整链接有效.对不起,非常感谢你! (8认同)
  • 我有同样的问题,我的所有路径都设置正确,只是抛出了同样的错误。 (2认同)

Sac*_*hin 7

我也陷入了同样的问题,我按照简单的步骤 - >

只需获取您要复制的文件的确切网址Ex->

http://www.test.com/test.txt (file to copy)
Run Code Online (Sandbox Code Playgroud)

使用文件名传递确切的绝对文件夹路径,您要在哪里写入该文件

1->如果你在Windows机器上然后 d:/xampp/htdocs/upload/test.txt

2->如果你在linux机器上那么 /var/www/html/upload/test.txt

你可以通过PHP函数 - >获取docuement根目录

$_SERVER['DOCUMENT_ROOT']
Run Code Online (Sandbox Code Playgroud)