Everything after this should be wrapped in a try/catch with an fclose on the catch.