Renaming duplicate files in a folder with php
<p>Who can help me to fix the following problem? Here is the issue: in a form POST i made people can upload files. The code below check if in the "uploads" folder there another file with the same name. If so, files are renamed as this example:</p>

<pre><code>hallo.txt
1_hallo.txt
2_hallo.txt
</code></pre>

<p>... and so on.</p>

<p>This is the code used:</p>

<pre><code>$OriginalFilename = $FinalFilename = $_FILES['uploaded']['name'];
// rename file if it already exists by prefixing an incrementing number
$FileCounter = 1;
while (file_exists( 'uploads/'.$FinalFilename ))
$FinalFilename = $FileCounter++.'_'.$OriginalFilename;
</code></pre>

<p>I would like to rename files in a different way. progressive numbers should be AFTER the file and, of course, before the extention. This is the same example of before but in the way i want:</p>

<pre><code>hallo.txt
hallo_1.txt
hallo_2.txt
</code></pre>

<p>... and so on.</p>

<p>How can i modify the code to reach that result?
Thank you in advance and sorry for my newbie-style question. I'm really newbie! :)</p>

<p>Mat</p>
