I need to write to a new flat file. I keep getting a "Permission Denied" message on what I'm trying now. What I want to do is to gather some information in a form, write it to a database and also to a flat file. The reason is to keep teachers from having to enter assignments into my form and then turn around and re-type the same information in for another part of the website that I don't have any control over. They want an html file and so I'm creating it for them. Anyway the write to the database part works like a charm. But this has got me frustrated. I hate flat files 😃
I also want to put this in a different folder same level as where this php code is. My php code is is /admin/ and I want to write this file to a folder called /assignments/ same level as /admin/. Here's what I have:
$filename = "/usr/home/mysite/public_html/htdocs/assignments/".
$courseOUT."_".$form['year1'].$fnMonth.$fnDay.".html";
chmod ($filename, 0666);
if (!$fp = fopen($filename, 'w')) {
echo "Cannot open file: ".$filename."<hr>".$htmlIN."<br>\n";
exit;
}
if (!fwrite($fp, $htmlIN)) {
print "Cannot write to file: ".$filename."<br>\n";
exit;
}
echo "Success, wrote: <hr>".$htmlIN."<hr> to file: ".$filename."<br>\n";
fclose($fp);
I get these error messages:
Warning: chmod failed: No such file or directory in
/usr/home/mysite/public_html/htdocs/admin/assignments.php
on line 661
Warning:
fopen("/usr/home/mysite/public_html/htdocs/assignments/Eng8_20021209.html", "w")
- Permission denied in
/usr/home/mysite/public_html/htdocs/admin/assignments.php on line 662
Cannot open file:
/usr/home/mysite/public_html/htdocs/assignments/Eng8_20021209.html