moved the file close inside the if/else statment 

on line 72 the fclose() is happening even if the file is not openned.
I moved the close inside the else statment so file is closed only if it was opened.

Note to the author : you better use something else (iframe ?) to let the browser open the page instead of using a fopen....