Copy link to clipboard
Copied
I have a php gallery populated from a folder of thumbnails and slides like this.
GALLERY/
+thumbs
01.gal.jpg
02.gal.jpg
03.gal.jpg
+slides
01.gal.jpg
02.gal.jpg
03.gal.jpg
Works as expected on my local testing server but my live page is displaying images in random order: 11., 04., 10., 02., etc...
My test page with PHP code.
http://alt-web.com/GALLERY/GalleryTest.php
How do I invoke natsort into my existing PHP code? Everything I've tried so far has failed.
Thanks,
Nancy O.
Thanks for that Rob.
I finally found a solution. Although I had an array called $file_parts, I needed to create another array to sort. Not exactly elegant, but it works.
http://alt-web.com/GALLERY/GalleryTest.php
Nancy O.
Copy link to clipboard
Copied
Perhaps what you want is natcasesort($fileList)
Copy link to clipboard
Copied
Thanks Rob. But that doesn't work either.
I must be overlooking something else in my coding but I don't know what.
Nancy O.
Copy link to clipboard
Copied
Here is an example of code I use with this function. natcasesort gives a more correct alphabetical sort, so I thought that might have been the issue.
function galleryDisplay($path, $dirpath) {
$handle = opendir($path);
$fileList = array();
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
array_push($fileList,$file);
}
}
closedir($handle);
natcasesort($fileList);
foreach ($fileList as $value) {
echo "<div class='image_item'><img src='$path/$value' draggable='true'/><br/>";
echo "<div><a href='images.php?messagebox=delete_image&value=$value&dirpath=$dirpath'>DELETE</a>";
echo "<a href='images.php?messagebox=open&value=$value&dirpath=$dirpath'> | VIEW</a><br/> $value</div></div>";
}
}
Copy link to clipboard
Copied
Thanks for that Rob.
I finally found a solution. Although I had an array called $file_parts, I needed to create another array to sort. Not exactly elegant, but it works.
http://alt-web.com/GALLERY/GalleryTest.php
Nancy O.