I have searched for almost similar questions but none of those gave me the right answer. I have a fully working file_exist code in if else statement he
With onclick= you assign a JavaScript event handler, not a PHP function.
onclick=
I don't know what your code is supposed to do, but perhaps you can execute the function when something is POSTed to your file.