here's my code. But the read(): in the while loop does not seems to sort my result aphabetically. Is there a way to sort my result? tks Seby
<?php
$save_path_folder_images = '../simplegallery/users/'.$_SESSION['user_id'].' /'.$_REQUEST['gal_folder'].'/thumbs/';
$save_path_folder_images_full = '/simplegallery/users/'.$_SESSION['user_id'].'/'.$_REQUEST['gal_folder'].'/slides/';
$folder=dir($save_path_folder_images);
$counter = 1;
while($folderEntry=$folder->read())
{
if($folderEntry!="." && $folderEntry!="..")
{?>
<div class="imgs" >
<div class="thumb" >
<label for="img<?php echo $counter; ?>"><img class="img" src="<?php echo $save_path_folder_images.$folderEntry; ?>" /></label>
</div>
<div class="inner">
<input type="checkbox" class="chk " id="img<?php echo $counter; ?>" name="img_name[]" value="<?php echo $save_path_folder_images_full.$folderEntry; ?>" />
</div>
</div>
<?php
$counter++;
}
}
?>
->read()
does not attempt to sort the output, you could loop through read()
once, pushing the output into an array. Then run it through natcasesort()
(http://php.net/natcasesort) to sort the array, then print it out.
So two loops.
while($folderEntry=$folder->read())
{
$fileList[] = $folderEntry;
}
natcasesort($fileList);
foreach($fileList as $folderEntry)
{
//your printing
}
Why don't you use DirectoryIterator?
$files = array();
$dir = new DirectoryIterator($save_path_folder_images);
foreach ($dir as $fileinfo) {
if ($fileinfo->isFile()) {
$files[] = $fileinfo->getFilename();
}
}
natcasesort($files);
check this thread as well Sorting files with DirectoryIterator