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
It's not possible to call a PHP-Function with onclick (directly) without reloading/loading the page.
But you can use tag for alternative solution and call that PHP function.