dbconnect();
if($_POST['linkuri'] != "")
	foreach($_POST['linkuri'] as $link)
	{
		$link_code="";
		do
		{
		$link_code = $adm1n->getRand(5);
		$result = $adm1n->qry("SELECT LinkCode from links where LinkCode=".$link_code);
		}
		while(mysql_num_rows($result)>0);
		
		$qry = "INSERT INTO links (LinkCode, Name, Address, Position, SubmenuCode) VALUES (".$link_code.", '".$link."', '".$link."', 'bottomend', ".$submenu." )";
		$insertLinks = mysql_query($qry) or die ("Insert error: 1 ".mysql_error());
	}
$adm1n->dbconnect();
while(list($key,$value) = each($_FILES[upfile][name]))
{
	if(!empty($value))
	{
		$filename = $value;
		//display
		echo '- '.$filename.' - Uploading...';
		$filename=str_replace(" ","_",$filename);
		
		$res_dir = $adm1n->qry("select m.Name, s.SubmenuName from menu_element as m inner join submenu_element as s on m.MenuCode=s.MenuCode where s.SubmenuCode=".$submenu." and m.MenuCode=".$menu);
			$row_dir = mysql_fetch_array($res_dir);
			$menuName=str_replace(" ", "_", $row_dir['Name']);
			$menuSubname=str_replace(" ", "_", $row_dir['SubmenuName']);
			$dir_path=$menuName."/".$menuSubname."/";
			$dir_path = str_replace(" ", "_", $dir_path);
			if(!file_exists("upload/".$dir_path))
			{
				if(!file_exists("upload/"))
				{
					mkdir("upload/");
					chmod("upload/", 0777);
				}
				if(!file_exists("upload/".$menuName."/"))
				{
					mkdir("upload/".$menuName."/");
					chmod("upload/".$menuName."/", 0777);
				}
				if(!file_exists("upload/".$dir_path))
				{
					mkdir("upload/".$dir_path);
					chmod("upload/".$dir_path, 0777);
				}
			}
		
		$add = "upload/".$dir_path."$filename";
		copy($_FILES[upfile][tmp_name][$key], $add);
		chmod($add, 0777);
		//display
		echo ' - Done...
';
		$file_code="";
		do
		{
		$file_code = $adm1n->getRand(5);
		$result = $adm1n->qry("SELECT FileCode from files where FileCode=".$file_code);
		}
		while(mysql_num_rows($result)>0);
		
		$qry = "INSERT INTO files (FileCode, Name, Address, Position, SubmenuCode) VALUES (".$file_code.", '".$filename."', '".$add."', 'bottomend', ".$submenu." )";
		$insertFiles = mysql_query($qry) or die ("Insert error: 2 ".mysql_error());
	}   
}
echo "";
?>