Get familiar with the annotated manual at www.php.net. It is your friend. The manual is well written (as manuals go) and the user annotations often cover angles that weren't adequately explained.
See
http://www.php.net/manual/function.fopen.php
Other filesystem functions are documented through links on the left side of the page.
The basic functions are:
fopen: opens a file; you specify whether it is read/write/append.
fread: reads from a file descriptor opened by fopen.
fwrite: writes to a file descriptor opened by fopen.
fclose: closes the file descriptor opened by fopen.
If you are working on a Unix platform, be sure that you have permission to write to the file or directory before trying to do so.
I have some examples of file annotation (guestbooks, basically) on my Web site; see http://yelvington.com/annotate.php3.