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
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.
Your above error message says, it wants to put the contents to a file in the directory
/files/grantapps/
, which would be beyond yourvhost
, but somewhere in the system (see the leading absolute slash )You should double check:
/home/username/public_html/files/grantapps/
really present./home/username/public_html/files/grantapps/
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->
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
and2->if u r on linux machine then
/var/www/html/upload/test.txt
and u can get the docuement root by the PHP function->