file_exists() works on local filenames of the server, so you have to prepend the directory part of $_SERVER['SCRIPT_FILENAME'] when you want to use an absolute path (or $_SERVER['DOCUMENT_ROOT'], if your script is in the toplevel directory). Relative pathnames are always troublesome; the current directory may not always be the same as where the script is located.