function getFileExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
} // getFileExtension
function getFileName($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
return substr($str,0,$i);
} // getfilename
$archivo = $_FILES ['foto']['name']; // agregado según tu código.
if (is_file($archivo)) {
$a = 0;
do {
$a++;
$archivo = GetFileName($archivo).$a.".".GetFileExtension($archivo);
} while (is_file($archivo));
}
echo $archivo;