Wow! This is a very old thread.
Since my question I have been able to write to text files. chmod is an ftp function that will change the mode (read-write permissions) of a file. Although I know what thsi is, I couldn't figure out how to use it and then I discovered I didn't really need to do it anyway.
Turns out php ususally has permissions to write to a directory on the web server.
Here is the code I use:
// The file will be prepended.
if (!$handle = fopen($filename, 'a')) {
print "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (!fwrite($handle, $somecontent)) {
print "Cannot write to file ($filename)";
exit;
}
fclose($handle);