Add this code and test it:
while(file_exists($uploadpath)){
//get filename without suffix
$rootname = basename($_FILES['fileup']['name'], $type);
//add $i to the file name between rootname and extension (suffix)
$uploadpath = "upload/".$rootname."-$i.".$type;
$i++;
}
Add it like this:
if($err == '') {
$i = 1;
while(file_exists($uploadpath)){
//get filename without suffix
$rootname = basename($_FILES['fileup']['name'], $type);
$uploadpath = "upload/".$rootname."-$i.".$type;
$i++;
}
if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {
echo '<font color="green"><b>Success!</b></font>';
echo '<br/>File: <b>'. basename( $_FILES['fileup']['name']). '</b>';
echo '<br/>File type: <b>'. $_FILES['fileup']['type'] .'</b>';
echo '<br />Size: <b>'. number_format($_FILES['fileup']['size']/1024, 3, '.', '') .'</b> KB';
echo '<br/><br/>File path: <input type="text" value="http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'" readonly>';
}
else echo '<b>Unable to upload the file.</b>';
}