Just a suggestion--I've found that giving each file the same amount of digits in the number makes for easier sorting, easier-to-read listings, better file listing, etc., and I'd remove the extraneous "jpg" for easier matching. This one-time routine will do that, and allow for up to 999 files (change the 7 to an 8 for up to 9999 files, of course):
$arr_1 = array ('10.jpg', '11.jpg',
'1.jpg', '2.jpg'); // etc.
$arr_2 = array ('th_10jpg.jpg', 'th_11jpg.jpg',
'th_1jpg.jpg', 'th_2jpg.jpg'); // etc.
foreach ($arr_1 as $key => $value) {
$len = strlen($value);
if ($len < 7) {
for ($i = 0; $i < (7 - $len); $i ++) {
$arr_1[$key] = '0' . $arr_1[$key];
}
}
rename('dir/' . $value, 'dir/' . $arr_1[$key]);
echo $arr_1[$key] . '<br />';
}
foreach ($arr_2 as $key => $value) {
$arr_2[$key] = str_replace('jpg.', '.', $value);
$arr_2[$key] = str_replace('th_', '', $arr_2[$key]);
$len = strlen($arr_2[$key]);
if ($len < 7) {
for ($i = 0; $i < (7 - $len); $i ++) {
$arr_2[$key] = '0' . $arr_2[$key];
}
}
$arr_2[$key] = 'th_' . $arr_2[$key];
rename('dir/' . $value, 'dir/' . $arr_2[$key]);
echo $arr_2[$key] . '<br />';
}
It's not real efficient coding, but you'd need to use it only once. (I'd comment out the "rename()" lines first to see that it works right; it does for me.)