function my_rename($dirname)
{
$ext_arr = array('jpeg', 'jpg', 'gif');
$dir = opendir($dirname);
$count = 1;
while (($file = readdir($dir)) !== false) {
if (is_file($dirname . '/' . $file)) {
$info = pathinfo($dirname . '/' . $file);
if (in_array(strtolower($info['extension']), $ext_arr)) {
rename($dirname . '/' . $file, $dirname . '/' . str_pad($count, 3, '0', STR_PAD_LEFT) . '.' . strtolower($info['extension']));
$count ++ ;
}
} elseif (is_dir($dirname . '/' . $file) && $file != '.' && $file != '..')my_rename($dirname . '/' . $file);
}
closedir($dir);
}