Can you try the code the way i have written don't change it place it has it is and try it out
function findexts ($filename) {
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1; $exts = $exts[$n];
return $exts; }
$ext = findexts ($_FILES['foto']['name']) ;
$ran2 = $foto.".";
$target = "../images/";
$target = $target . $ran2.$ext;
while (file_exists($target)) {
$ran2 = 'copyof'.$ran2;
$target = $target . $ran2.$ext;
}
if(move_uploaded_file($_FILES['foto']['tmp_name'], $target)) {
$newFilename = $ran2 . "." . $ext;
mysql_query( "INSERT INTO `softmarket`.`internet_securitate` (`internet_securitateID`, `nume_produs`, `descriere`, `versiune`,`poza`, `pret`, `disponibilitate_produs`)
VALUES ('', '$_POST[titlu]', '$_POST[descriere]', '$_POST[versiune]', '$newFilename', '$_POST[pret]', '$_POST[disponibilitate]');");
echo "The file has been uploaded as ".$newFilename; }
else { echo "Sorry, there was a problem uploading your file."; }
header('Location: succes.php');