创建一个继续下一个号码的目录?

I'm Trying to have this button create a directory "item1" and when the button is clicked again, it creates "item2" and so on, for unlimited amount of times.

So far I have this for html (basic):

    <!DOCTYPE html>
<html>  
   <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
   </head>
   <body>
      <form id="create_item" action="createfile.php" method="POST" enctype="multipart/form-data">
         <input id="submit_button" type="submit" value="Create Item!" />
      </form>     
   </body>
</html>  

And my php code:

<?php
define("PATH", "/usr/www/tfgwebsite/public/misc/phptest");

$number = 1;
$_POST["dirname"] = "item" . $number;
$test = "set";

if (isset($test)) {
    $dir = $_POST['dirname'];
}

$targetfilename = PATH . '/' . $dir;

if (!is_file($dir) && !is_dir($dir)) {
    mkdir($dir);
    chmod($targetfilename, 0777);
    echo "Created " . $dir . " successfully!";
}
else
{
    echo "File already exists!";
}?>

I have tried literally about 80 different combinations of for loops and while statements to try to get $number to increase by 1 if it finds an existing directory, all of them end up creating item1, then infinite looping on me.

Any help would be appreciated, I would post all the things I've tried to show you that I have indeed tried, but they are so hideous, I can't even bear to show such horrible code.

EDIT:

<?php
define("PATH", "/usr/www/tfgwebsite/public/misc/phptest");

$items = fopen("items.txt", "r") or die("Unable to open file!");
$number = fgets($items);
fclose($items);

$_POST["dirname"] = "item" . $number;
$test = "set";

if (isset($test)) {
    $dir = $_POST['dirname'];
}

$targetfilename = PATH . '/' . $dir;

if (!is_file($dir) && !is_dir($dir)) {
    mkdir($dir);
    chmod($targetfilename, 0777);
    echo "Created " . $dir . " successfully!";
    $create = fopen("items.txt", "w+") or die("Unable to open file!");
    fwrite($create, $number + 1);
    fclose($create);
}
else
{
    echo "File already exists!";
}

?>

I did this, and it does work. But I do have this awkward .txt in my webserver just counting up, lol.

If there is a better method, please share.

Please take a look into this code .This is working for me.

-- UPDATED CODE --

<?php
if (!empty($_POST)) { //print_r($_POST);die;
    define("PATH", $_SERVER['DOCUMENT_ROOT'] . "/create_folder/");

    $files2 = array_diff(scandir($_SERVER['DOCUMENT_ROOT'] . "/create_folder/"), array('..', '.', '.svn'));
    $count = count($files2);
    $count_plus = $count + 1;
    if (!is_file(PATH . "item$count_plus") && !is_dir(PATH . "item$count_plus")) {
        mkdir(PATH . "item$count_plus");
        chmod(PATH . "item$count_plus", 0777);
        echo "Created item" . $count_plus . " successfully!";
    } else {

        echo "File already exists!";
    }
}
?>
<!DOCTYPE html>
<html>  
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    </head>
    <body>
        <form id="create_item" action="" method="POST" >
            <input id="submit_button" type="submit" name ="create_folder" value="Create Item!" />
        </form>     
    </body>
</html> 

This code works like this-

It will define PATH constant for location where folders are getting created.

Then it will scan that folder

Then it will check if next folder is present in that directory OR not.

if not then it will create that folder otherwise will give an error.