Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts

    Exclamation problems reading files from directory - doesnt display in order :(

    Hi All,

    I have a gallery php page which gathers the photos from a specified directory or images, it is working ok but the major probem im having is that it doesnt always display the files in order.

    By this i mean if my images are titled img0, img1, img2 .... img10, img11, img12

    they are ordered like so
    img0, img1, img10, img11, img12, img2

    and not like
    img0, img1, img2, img10, img11, img12

    does anyone know how to fix this?

    here is my code
    PHP Code:
                <?php
                
    if(isset($is_gallery))//has the user opened a portfolio category
                
    {
                    
    $breadcrumbs "<a href='portfolio.php'>Portfolio</a>"." / "."<a href='portfolio.php?gallery=$is_gallery'>".ucwords($is_gallery)."</a>";
                    echo 
    $breadcrumbs;
                    
    #echo "<h3>".ucwords($is_album)."</h3>";
                    
    $dir "portfolio/".$is_gallery;
                    
    $dir2 $dir."/";    
                                                    
                    echo 
    "<h3>".$is_gallery." Gallery</h3>";
                    
    $count 0;
                    
    //display thumbs
                    
    if ($handle opendir($dir))
                    {
                        
    $x 1;?>
                        <div class='wrapper'>
                        <ul class='gallery clearfix'>
                        <?php
                        
    while (false !== ($entry readdir($handle)))
                        {
                            if(
    $entry != "." && $entry != ".." && strpos($entry,"."))
                            {
                                
    $default_file $dir."/".$entry;
                                
    $target_file $dir."/".$entry;
                                
    $kaboom explode("."$target_file); // Split file name into an array using the dot
                                
    $fileExt end($kaboom); // Now target the last array element to get the file extension
                                
    $resized_file $dir."/resized/".$entry;
                                
    $wmax 250;
                                
    $hmax 250;
                                
    ak_img_resize($target_file$resized_file$wmax$hmax$fileExt);
                            
                                
    // ----------- End Adams Universal Image Resizing Function ----------
                                // ------ Start Adams Universal Image Thumbnail(Crop) Function ------
                                
    $target_file $resized_file;
                                
    $thumbnail $dir."/thumbs/".$entry;
                                
    $wthumb 150;
                                
    $hthumb 150;
                                
    ak_img_thumb($target_file$thumbnail$wthumb$hthumb$fileExt);
                                    
                                
    $filename explode(".",$entry);
                                
    $filename $filename[0];?>
                                <div class="gallery-image">
                                    <figure class="img-box">
                                    <li>
                                        <a class="lightbox-image" href="<?php echo $default_file?>" rel="prettyPhoto[]" title="<?php echo $desc;?>">
                                        <img src="<?php echo $thumbnail?>" width="150" height="150" alt="<?php echo $alt?>" title="<?php echo $alt?>" /></a>
                                    </li>
                                    </figure>
                                </div><?php
                                $count
    ++;
                            }
                        }
    ?>
                        </ul>
                        </div><?php
                    
    }
                }
    any help would be greatly appreciated
    Thanks

    Luke

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    Age old problem because the sort reads from left to right. First the i, then the m, then the g and then the 1 (everything with a 1 in fourth slot).

    One way to do this is to sort by length first then by number.

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    hmm ok thanks! any idea how i can integrate the idea in to my above code? thanks

    Luke

  • #4

  • The Following 2 Users Say Thank You to gvre For This Useful Post:

    LJackson (02-23-2013), sunfighter (02-23-2013)

  • #5
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    @gvre Thanks for the heads up on natsort. Never know it existed.

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    thanks @gvre natsort is a life saver exactly what i was after!

    appreciate your time folkes!
    Luke


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •