Thank you very much for answering my question. I got it, except one thing. After list1.php exists, the final value does not return.
Here is my code. Kind of long and may be dumb. If you could advice me with any improvement, I will be much appreciated.
function changeFilename($newName, $file)
{
if ((settype($newName, "integer") >= 0) or (settype($newName, "integer") <= 9))
$newName++;
else
{
settype($newName, "integer");
$newName = 1;
}
$split = explode(".",$file);
if ($newName == 1)
$noext = substr("$file", 0, -4); //get the last word or number before the extension
else
$noext = substr("$file", 0, -5);
$newFile = $noext.$newName.".".end($split); //new file name
$chkfile_exists="/localhost/uploads/".$newFile;
if (file_exists($chkfile_exists))
changeFileName($newName, $newFile);
return $newFile;
}
//main file
$tempFile = $FILES['uploadFile']['tmp_name'];
$destination = "/localhost/uploads/". $FILES['uploadFile']['name'];
if (file_exists($destination))
{
$filename = $_FILES['uploadFile']['name'];
$fileincrement = substr("$filename", -5, 1);
$new = changeFilename($fileincrement, $filename);
copy ($tempFile, "/localhost/uploads/".$new);
}
else
{
copy ($tempFile, $destination);
}