在上传另一个同名文件时无法重命名预先上传的文件

I am unable to rename a pre uploaded image, say "file1.jpg", when uploading another file with the same name.

I am saving both files in a folder named "uploads" on the server's root folder. Thus, I need to rename the previous file name to something other and then save the new file as "file1.jpg". I have no idea about how to do this in PHP. Please, provide any hints or code if possible.