Run php function inside jQuery click

You cannot run PHP code inside a jquery function. PHP runs on the server-side whereas jquery/javascript runs on the client-side. However, you can request a PHP page using jquery and with the PHP code on that page will run the mkdir that you want.

JS:

$.ajax({
  url: 'test.php',
  success: function(data) {
    alert('Directory created');
  }
});

test.php FILE:

 <?php mkdir('/test1/test2', 0777, true); ?>

First of all you should understand how php works (no offense but this is essential). Why PHP script is not workig in a web browser? To accomplish what you need you have to use ajax (to request a script on the server using javascript)

PHP File (createdir.php):

<?php 
    mkdir('/test1/test2', 0777, true); 
?>

JavaScript Code:

$('button').click(function() {
    $.ajax({
        url: 'createdir.php',
        success: function(){
             alert('dir created');
        }
    });

    return false;
});

I have not validated if the code acually works. If you encounter any problems you should have a look at the jquery documentation (it's awsome :-) ) http://api.jquery.com/jQuery.ajax/