As per the request from Sourav, I've reposted my comments as a solution.
A couple of points that come to mind
■ You could download phpBB (free forum software) and look at the source
■ When uploading files, it (a) renames them (b) keeps track of the original name and the renamed name
■ using time() would give you a number you could convert to a string and use as a filename - though you would be limited to 1 upload per second or millisecond, whatever the resolution of time is (I forget)
■ You can just comment-out these 3 lines to remove the 'already exists' msg:
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
■ You could make the following change to rename the file:
$newFilename = calcNewNameForFile();
...
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/".$newFilename);
...