How about a first loop to temporarily rename all files with something like :
_filename-1000-1_t.jpg
_filename-1000-1.jpg
_filename-1000-12_t.jpg
etc…
Then, get the list of the files in the folder in alphabetical order and rename them according to what you need.
Something like:
// First, rename all the files temporarily with an underscore
$files = array();
$dir = opendir('.');
while(false != ($file = readdir($dir))) {
if(($file != ".") and ($file != "..") and ($file != "index.php")) {
rename($file, '_' . $file);
}
}
// Get all the files in an array
$files = array();
$dir = opendir('.');
while(false != ($file = readdir($dir))) {
if(($file != ".") and ($file != "..") and ($file != "index.php")) {
$files[] = $file; // put in array.
}
}
// Order the files alphabetically
natsort($files);
// Rename the files
$fileIndex = 0;
foreach($files as $file) {
$fileIndex++;
// Remove the temporary "_" + rename the number according to $fileindex
}