How do I write a file with PHP?

dyl

New member
I am trying to write a file using php. I copied this code, but when I try to run it from my webpage I get a "Internal Server Error"

<?PHP

$filename = "output.txt"; #Must CHMOD to 666
$text = $_POST['Email']; # Form must use POST. if it uses GET, use the line below:
#$text = $_GET['theformfieldname']; #POST is the preferred method

$fp = fopen ($filename, "w"); # w = write to the file only, create file if it does not exist, discard existing contents
if ($fp) {
fwrite ($fp, $text);
fclose ($fp);
echo ("File written");
}
else {
echo ("File was not written");
}

?>
Unfortunently I tried copying the code you posted, but I still get an internal server error
 
Back
Top