Hi,
if you use a+ with fopen it already does what you want, e.g.
$fp = fopen("thefile.txt","a+");
That opens the file and places the file pointer at the end of the file. If you use then e.g. fputs it would write to the end of the file.
If the file doesn't exist fopen will create a new one.