$picture_name = strtolower(str_replace(" ", "_", $_FILES[$tempname]["name"])); $pos = strrpos($picture_name, "."); $name = substr($picture_name, 0, $pos); $ext = substr($picture_name, $pos + 1); if (file_exists($folder.$picture_name)) { $taskDone = false; for ($i = 1; (($i < 500) && ($taskDone == false)); $i++) { if (!file_exists($folder.$name."_".$i.".".$ext)) { if (is_uploaded_file($_FILES[$tempname]['tmp_name'])) { if (move_uploaded_file($_FILES[$tempname]['tmp_name'], $folder.$name."_". $i.".".$ext)) { SetRightsToUploadedFile($folder.$name."_".$i.".".$ext); $new_tempname = $name."_".$i.".".$ext; } } $taskDone = true; } } } else { if (is_uploaded_file($_FILES[$tempname]['tmp_name'])) { if (move_uploaded_file($_FILES[$tempname]['tmp_name'], $folder.$picture_name)) { SetRightsToUploadedFile($folder.$picture_name); $new_tempname = $picture_name; } } } } return $new_tempname; } ?>