hey,
I am writing some script so that when a user signs up, they can create their own folders on the server. I Know the code to do that, but I need some help with the following:
when they enter a folder name to create.. it checks the main folder for that name. If it exists, the script should then tell the user, and offer them alternatives. eg: I enter "matt" as my folder name, the script should say "sorry, that folder already exists. You could have 'matt1', 'matt2' etc.... or please enter another name" ... kinda like the hotmail sign up page...
neway.. here's the code I have so far.
<?php
/* MAKE FOLDER */
$folder_name = $_POST['folder_name'];
//check if folder exists
$test = is_dir("../" . $folder_name);
if ($test) //found a dir
{
echo "oops. there is already a folder of that name<BR><BR>You could try some of the following:<BR><BR>";
$test2 = is_dir("../" . $folder_name);
while (!$test2) //not found a name
{
//while there are matches, get the foldername, and add 1...once we get a match, we will use that name.
$new_folder_name = $folder_name . "" . $i;
echo $new_folder_name . "<BR>";
$test2 = is_dir("../" . $new_folder_name);
$i++
}
//clear the cache of the foldername
clearstatcache();
}
else
{
echo "The foldername: ". $folder_name . " does not exist!! GREAT!! ok!";
}
?>
Basically, I wanted a loop which says "while the foldername doesnt exist, add one" or something.... but only do that upto 5 times.. otherwise it'll create an infinate loop!!
Any help will be much appreciated!!
thanks!!