phatmambo Posted February 23, 2012 Share Posted February 23, 2012 I have a very simple piece of code to create a grid based gallery. The thumbnails are loaded from a single directory and are name 1.jpg... 2.jpg... 3.jpg etc At the moment the images appear to be loaded in randomly. I want them to load in numerically in terms of their filename. I know I may need to use 'sort' or 'natsort' but where in the code? Thanks for any help you can give me <? $images = "Images/Bag Thumbs/"; # Location of small versions $big = "ruxxwomens.php?id="; # Location of big versions (assumed to be a subdir of above) $cols = 4; # Number of columns to display if ($handle = opendir($images)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != rtrim($big,"/")) { $files[] = $file; } } closedir($handle); } $colCtr = 0; echo '<table width="800" cellspacing="0" cellpadding="0" border="0"><tr>'; foreach($files as $file) { if($colCtr %$cols == 0) echo '</tr><tr>'; echo '<td align="center"><a href="' . $big . $file . '"><img src="' . $images . $file . '" cellspacing="0" cellpadding="0" border="0"></a></td>'; $colCtr++; } echo '</table>' . "\r\n"; ?> Link to comment https://forums.phpfreaks.com/topic/257617-simple-image-gallery-reading-from-directory-random-numerical-placement/ Share on other sites More sharing options...
dragon_sa Posted February 23, 2012 Share Posted February 23, 2012 put here if ($handle = opendir($images)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != rtrim($big,"/")) { $files[] = $file; } } sort($files); closedir($handle); } Link to comment https://forums.phpfreaks.com/topic/257617-simple-image-gallery-reading-from-directory-random-numerical-placement/#findComment-1320378 Share on other sites More sharing options...
phatmambo Posted February 23, 2012 Author Share Posted February 23, 2012 Brilliant. That was easy. Thanks Link to comment https://forums.phpfreaks.com/topic/257617-simple-image-gallery-reading-from-directory-random-numerical-placement/#findComment-1320381 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.