What you need is a solution like AJAX. Once the user clicks on the button, you make a request to your PHP script which then return a value based on which you can take the next step.
Here's an example on how to achieve that using the jquery library.
$('#form').submit(function(event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: 'file-exists.php',
data: $(this).serialize(),
dataType: 'json', // could be plain-text as well; depends on your use-case
success: function (data) {
console.log(data);
//do whatever you want based on this data
}
});
});
You could also avoid using the library as well, but that would have made it more complicated to explain. You could read more about how to go about doing that, here: http://blog.mgechev.com/2011/07/21/ajax-jquery-beginners/