PHP Images rename double digits
<p>I have pictures in a folder and I would like to rename them sequentially to a two digit number. I browsed and tried a lot of solutions but I didn't manage to find what I am looking for. I grown desperate now. I managed to find this code but it renames one digit from 1 to 9, and two digits from 10 onward. I would like it to numerate starting 01.jpg, 02.jpg, 03.jpg, etc...</p>

<pre><code>&lt;?php

$files = glob('../thumbs/*');

foreach($files as $i =&gt; $name) {
    $newname = sprintf('../thumbs/%d.jpg', $i+2);
    if ($newname != $name) {
        rename($name, $newname);
    }
}


?&gt;
</code></pre>

<p>How can I modify the above code to make it a double digit?</p>
