Q:

How to create and name a folder each time a file is uploaded in PHP?

How do i create a folder for each upload but auto number it when each folder is created?
lets say i upload a file then a folder 1 is created inside the uploaded folder, then someone else or the same person uploads another file then a folder 2 will be created in the uploaded folder? Is there any way to do this?
Here is what i have right now
$name = $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];

move_uploaded_file($temp,"uploaded/".$name);
$url = "www.Mysite.com/uploaded/$name";
mysql_query("INSERT INTO `asktemp` VALUE ('','$suserid','$askeduserid','$name','$url')");

A:

You can do this:
$upload_dir = 'uploaded/';
$dir = 1;
while(file_exists($upload_dir.$dir) and is_dir($upload_dir.$dir)) {
    $dir++;
}
mkdir($upload_dir.$dir);

That creates directories like 1,2,3 etc
And then just put:
move_uploaded_file($temp,$upload_dir.$dir.'/'.$name);

to upload your file to the new created directory.

