Looks fine to me... why do you say that it isn't working? Once you sort the folder list, you never do anything with it..
EDIT: Also, you could simplify your code a lot if you just used [man]glob/man. For example, all of this:
$dh = opendir($dirr);
while (false !== ($filename = readdir($dh))) {
if ($filename != "." && $filename != "..") { // remove the move up directory commands. (. and ..)
$files[] = $filename;
// ...
}
sort($files)
could be replaced by this:
$files = glob('*.*');