<? php
// Creating the file
$newfile=(fopen(/usr/local/apache/htdocs/mydata.txt","a+");
fwrite($newfile,"this is a new file,");
fclose($newfile);
//Reading the file
// contains the full path to the file
$file_loc="/usr/local/apache/htdocs/mydata.txt";
// open the file for read only
$whattoread=fopen($file_loc,"r");
// Puts contents of entire file into a variable
$file_contents=fread($whattoread, filesize($file_loc));
// close the file
fclose($whattoread);
echo "the file contains: $file_contents";
// Writing back to the datafile
$rewrite=(fopen(/usr/local/apache/htdocs/mydata.txt","a+");
fwrite($rewrite,"this is a new file,");
fclose($rewrite);
Notice the Create and the Writing code is the same except for the file name.