probably easy fwrite question
Posted: Thu Jul 22, 2004 12:17 pm
Hello
I'm new with PHP and I was trying to append to a file. this is what I have
test.php
thats from the manual. I also have a file called test.txt with all access rights on. when I run this script I get "Success, wrote (Add this to the file) to file (test.txt) " but test.txt is still blank.
any ideas what I did wrong?
I'm new with PHP and I was trying to append to a file. this is what I have
test.php
Code: Select all
<?php
$filename = 'test.txt';
$somecontent = "Add this to the file";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>any ideas what I did wrong?