1) Look at the manual. There is plenty of information about it.
The data posted by a form are stored in a variable with the same name of the formfield.
You can write anything to textfiles if you look at functions like fopen() and fwrite().
2) Reading a random line... generate a random number, look at fopen(), fread(), fgets().
You will probably have to OR include a field (column) in the textfile to tell PHP if it is a quote or an image-url it is reading OR insert the right code for loading the image (Html-code that is) in the textfile so that PHP can just write that code. Think the first option is the best.
Something like
Text \t (tabspace) Your text
Image \t Url-to-image
If you have come up with something, feel free to post. However, don't expect us to build your code...