Fix 1: disable register_globals.
It is important that all PHP apps have register_globals disabled. This is because otherwise there are HEAPS of possible attacks. Also it makes code clearer, using $GET and $POST rather than globals.
I'd recommend your application test for register_globals (use ini_get), and if it's enabled, throw an error message and exit. May as well do magic_quotes too (magic_quotes are evil)
That will prevent register_globals from accidentally being re-enabled in the future.
Secondly, you should on no account allow user input to directly affect the directory read, or the file read.
In the case where you genuinely want to read the file from the query string, create a list of allowed files and if it isn't one of them, don't allow it.
Check any paths from the user for containing only valid characters using a regular expression. Normally I'd recommend you stick to [a-z0-9.]+$
Also check it for presence of strings which could indicate a problem, for instance "..". Or perhaps build the regexp so that it only allows a single .
Finally, don't give users a different error message if a file doesn't exist, or if an input validation error occurs, so they can't use it to explore the rules or test for the existence of files independently.
Mark