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.
我正在尝试使用dompdf将一个表单保存到一个易读的.pdf文件中,我的处理脚本如下。我收到了错误警告:file_put_contents(/files/grantapps/NAME0.pdf)[功能。文件-放置-内容]:未能打开流:在/home/username/public_html/subdir/apps/dompdf/文件名中没有此类文件或目录。php在39行。(第39行是我全文的最后一行。)我不知道如何解决这个问题。
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.
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());
2 个解决方案
#1
31
There is definitly a problem with the destination folder path.
目标文件夹路径肯定存在问题。
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 )
上面的错误消息说,它希望将内容放到目录/文件/grantapps/中,该文件将超出您的vhost,但是在系统中的某个地方(见领先的绝对斜杠)
You should double check:
你应该仔细检查:
- Is the directory
/home/username/public_html/files/grantapps/
really present. - 目录/home/username/public_html/files/grantapps/真的存在吗?
- Contains your loop and your file_put_contents-Statement the absolute path
/home/username/public_html/files/grantapps/
- 包含循环和file_put_content-语句绝对路径/home/username/public_html/files/grantapps/
#2
5
I was also stuck in the same kind of problem and i follow the simple step->
我也陷入了同样的问题,我遵循简单的步骤——>
just get the exact url of the file to which u want to copy Ex->
只需获取您想要复制Ex->的文件的准确url
http://www.test.com/test.txt (file to copy)
and pass the exact absolute folder path with filename where do u want to write that file
并传递带有文件名的绝对文件夹路径
1->if u r on windows machine then d:/xampp/htdocs/upload/test.txt
and
1->如果你在windows机器上使用u r,那么d:/xampp/htdocs/上传/测试。txt和
2->if u r on linux machine then /var/www/html/upload/test.txt
2->如果你在linux机器上,那么/var/www/html/upload/test.txt。
and u can get the docuement root by the PHP function->
u可以通过PHP函数>得到docuement root
$_SERVER['DOCUMENT_ROOT']
#1
31
There is definitly a problem with the destination folder path.
目标文件夹路径肯定存在问题。
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 )
上面的错误消息说,它希望将内容放到目录/文件/grantapps/中,该文件将超出您的vhost,但是在系统中的某个地方(见领先的绝对斜杠)
You should double check:
你应该仔细检查:
- Is the directory
/home/username/public_html/files/grantapps/
really present. - 目录/home/username/public_html/files/grantapps/真的存在吗?
- Contains your loop and your file_put_contents-Statement the absolute path
/home/username/public_html/files/grantapps/
- 包含循环和file_put_content-语句绝对路径/home/username/public_html/files/grantapps/
#2
5
I was also stuck in the same kind of problem and i follow the simple step->
我也陷入了同样的问题,我遵循简单的步骤——>
just get the exact url of the file to which u want to copy Ex->
只需获取您想要复制Ex->的文件的准确url
http://www.test.com/test.txt (file to copy)
and pass the exact absolute folder path with filename where do u want to write that file
并传递带有文件名的绝对文件夹路径
1->if u r on windows machine then d:/xampp/htdocs/upload/test.txt
and
1->如果你在windows机器上使用u r,那么d:/xampp/htdocs/上传/测试。txt和
2->if u r on linux machine then /var/www/html/upload/test.txt
2->如果你在linux机器上,那么/var/www/html/upload/test.txt。
and u can get the docuement root by the PHP function->
u可以通过PHP函数>得到docuement root
$_SERVER['DOCUMENT_ROOT']