You're creating HTML code during directory listing, it's better to split those.
One method to get the contents, and one method to parse it into HTML code.
That way if you would ever change the listing methode (eg using 'glob' instead of opendir & readdir, you wouldn't have to change the code which creates the HTML code.
Further more if you split those, you could install another small xml or html-template if you liked.
And your starting to read as soon as you create an instance.
Don't start opening en reading of right away, cause you might want to 'configure' the class somehow (like only show image files).
At this point you're executing almost all class-methods when you create an instance.
That's quite procedural too 
Here's an idea:
PHP Code:
$dirlist = new DirectoryReader;
$dirlist->setValidTypes('jpg','gif','png');
$dirlist->readDir('/path/to/directory') or die($dirlist->getError());
$dirlist->setTemplate('<file><name>%1\$s</name><path>%2\$s</path></file>');
// start output
header('Content-Type: application/xml; charset=iso-8859-1');
print '<?xml version="1.0" encoding="iso-8859-1"?><files>';
$dirlist->printList();
print '</files>';
Most important is that your code remain flexible, reusable and readable
Bookmarks