auto rename of filename if already exist php code
<p><strong>upload.php</strong></p>

<pre><code>&lt;form enctype="multipart/form-data" action="uploader.php" method="POST"&gt;
Choose a file: &lt;input name="uploadedfile" type="file" /&gt;&lt;br /&gt;
Choose a file1: &lt;input name="uploadedfile1" type="file" /&gt;&lt;br /&gt;
&lt;input type="submit" value="Upload File" /&gt;
&lt;/form&gt;
</code></pre>

<p><img src="http://i.stack.imgur.com/BSRyH.jpg" alt="enter image description here"></p>

<p><em>image of the form upload.php</em></p>

<p><strong>uploader.php</strong></p>

<pre><code>mysql_select_db("test");


$target_path = "uploads/" . basename( $_FILES['uploadedfile']['name']);
$currentfile = $_FILES['uploadedfile']['name']; 
$target_path1 = "upload1/" . basename( $_FILES['uploadedfile1']['name']);
$currentfile1 = basename( $_FILES['uploadedfile1']['name']); 


$dbfiles = mysql_query("SELECT * FROM new WHERE amount='$currentfile' || amount='$currentfile1'");
if(mysql_num_rows($dbfiles) &gt; 0 )
{ 

//what code should i place here??    

}
else
{
        if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
        {
                echo "file1: ".$_FILES['uploadedfile']['name']."&lt;br&gt;";
                $file1 = basename( $_FILES['uploadedfile']['name']);
                mysql_query("insert into new (amount) values('$file1')");   
        }
        if(move_uploaded_file($_FILES['uploadedfile1']['tmp_name'], $target_path1))
        {
                echo "file2: ".basename( $_FILES['uploadedfile1']['name']);
                $file2 = basename( $_FILES['uploadedfile1']['name']);
                mysql_query("insert into new (amount) values('$file2')");   
        }
}
</code></pre>

<p>what code should i need to place inside of this if condition <code>if(mysql_num_rows($dbfiles) &gt; 0 ){ }</code> so that if the filename of the file that was uploaded was already exist, the file should change its filename automatically for example there was abc.jpg existing, then some one upload a new file but the name and type is same as abc.jpg.. then the newly file must be, abc_1.jpg... and if some one upload as same as abc.jpg, the name should be abc_2.jpg..
abc_1.jpg must be the name that will save to the mysql, and abc_1.jpg must the file that will save to the prepared folder.. thx </p>

<p>i get the idea and code here <a href="http://www.tizag.com/phpT/fileupload.php?MAX_FILE_SIZE=100000&amp;uploadedfile=NeroMediaHub._63C8A7B0BBE5459F9AC436392B2FF50D.exe" rel="nofollow">http://www.tizag.com/phpT/fileupload.php?MAX_FILE_SIZE=100000&amp;uploadedfile=NeroMediaHub._63C8A7B0BBE5459F9AC436392B2FF50D.exe</a></p>
