Rename all files in order in PHP
<p>I have the following files:</p>

<pre><code>1.jpg
2.jpg
3.jpg
4.jpg
</code></pre>

<p>When I remove <code>2.jpg</code>, I want <code>3.jpg</code> to become <code>2.jpg</code> and <code>4.jpg</code> to become <code>3.jpg</code></p>

<p>I tried a for loop with the <code>rename</code> function, but it does not seem to work:</p>

<pre><code>for($a = $i;$a &lt; $filecount;$a ++)
{
    rename('photo/'.($a+1).'.jpg', 'photo/'.   ($a).'.jpg');
}
</code></pre>

<p>Where <code>$i</code> is the number of the photo I just deleted.</p>
