Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Order of images in script


rainborick - 2:01 am on Jul 22, 2012 (gmt 0)


You're right. File systems' directories do not store the file names in any sorted order. I'm sure there's an explanation for how they do store them, but it doesn't matter. If you want to deal with files in a sorted manner (by file name, last modification date, creation date, or whatever), you need to do the sorting on your own. This generally means reading all of the file names into an array and then sorting that array as needed, as in something like:

<?php
$directory = 'images/slideshow';
try {
// Styling for images
echo "<div id=\"main\">";
$slidefiles = new DirectoryIterator($directory);
asort($slidefiles);
foreach ($slidefiles as $item ) {
if ($item->isFile()) {
$path = $directory . "/" . $item;
echo "<img src=\"" . $path . "\" />";
}
}
echo "</div>";
}
?>


Thread source:: http://www.webmasterworld.com/php/4477824.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com