I'll let you learn more from seeing actual documentation, instead of me writing out a teeny little script that leaves tons of "what ifs" in the air 😃
Head over to:
http://www.php.net/manual/en/function.fopen.php
On the left side of this page, will also show you all the wonderful functions you can use from that, and with that function of "fopen".
For question #1, the "readfile()" function would be good as a singular action.
For question #2, you will need to use the fopen fputs and fclose functions.