Assuming that there is only one person ever going to be entering records at a time a quick and dirty solution would be to have a recordset that returns the last id in the table and then add 1 to it.
Pseudo code would look like:
mysql_select_db($database_connDB, $connDB);
$query_rsGetLastID = "SELECT id FROM table ORDER BY id DESC LIMIT 1";
$rsGetLastID = mysql_query($query_rsGetLastID, $connDB) or die(mysql_error());
$row_rsGetLastID = mysql_fetch_assoc($rsGetLastID);
$totalRows_rsGetLastID = mysql_num_rows($rsGetLastID);
$nextID = $row_rsSortOrder['sortorder']+1;
Then use $nextID in your code to create directories etc. before doing the upload and insert.
If there is more than one person entering data then you would need a more robust solution.