I'm uploading images through PHP. I'm using the following segment of code:

PHP Code:
    if (file_exists("photos/" $_FILES["file"]["name"]))
$_FILES["file"]["name"] . " already exists. ";
What I'd like to do is instead of reporting an error saying the file name already exists, choose a different name for the file that's available. How do I assign a unique name to the file (for example, filename2.jpg, filename3.jpg)? I can do it using what I know about do while loops, but I'm not sure if there's a particularly simple or built-in way.