chrisrushing Posted February 19, 2010 Share Posted February 19, 2010 I'm trying to get the images in a directory and sort them numerically or alphabetically, whatever. And then just display them. I'm still sooooo new at php so i'm doing a lot of tutorials/copy/pasting trying to figure things out. I'm a designer at heart, please be nice. This is probably going to have to be completely rewritten to do so... It was from a tutorial so i copied/pasted most of it, and then edited what i needed. It totally works as is and displays the images, it just doesn't put them in order. I know I need to probably use sort($item,SORT_NUMERIC); but have no idea where to put it. Either way, I'm not quite getting this... any help is appreciated. <?php $directory = 'images' . $row['imageName']; try { echo "<div class=\"next\"><div id=\"work\" class=\"pics\">"; foreach ( new DirectoryIterator($directory) as $item ) { if ($item->isFile()) { $path = $directory . "/" . $item; echo "<img src=\"" . $path . "\" />"; } } echo "</div></div>"; } catch(Exception $e) { echo 'Whoops. Something did not work.'; } ?> Link to comment https://forums.phpfreaks.com/topic/192676-im-a-newb-get-sort-and-display-images-from-a-specified-directory/ Share on other sites More sharing options...
jorley Posted February 20, 2010 Share Posted February 20, 2010 Try the follwing. It will list the files in the directory out and make them clickable to open/download. Replace directory with you actual directory name. <?php $dir="directory"; // Directory where files are stored if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) //while there are files in the directory, do the following { ?> <p><a href="directory/<?=$filename?>"><?=$filename?></a></p> <?php } closedir($dir_list); } ?> Link to comment https://forums.phpfreaks.com/topic/192676-im-a-newb-get-sort-and-display-images-from-a-specified-directory/#findComment-1015116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.