Putting It All Together

The short piece of code in Listing 6-8 uses the DirectoryItems class together with the ThumbnailImage class to display all images within a directory, at reduced sizes.

Listing 6-8. Displaying all the images in a directory at reduced size
 <?php require 'DirectoryItems.php'; $dc = ❶new DirectoryItems('graphics'); $dc->imagesOnly(); $dc->naturalCaseInsensitiveOrder(); $path = ""; $filearray = $dc->getFileArray(); echo "<div style=\"text-align:center;\">"; echo "Click the filename to view full-sized version.<br />"; //specify size of thumbnail $size = 100; foreach ($filearray as $key => $value){ $path = "graphics/".$key; /*errors in getthumb or in class will result in broken links - error will not display*/ echo "<img ❷src=\"getthumb.php?path=$path&amp;size=$size\" ...

Get Object-Oriented PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.