Script to list images in descending order (from last to first)

0

Hello. I have this script that shows a list of images within a given folder, and lets you choose how many images to show per page. But if the files have the names 1.jpg 2.jpg 3.jpg, it shows in a crescent, 1,2,3 ... but what I wanted is to start at the last ... 3,2,1. .. How can I do this?

  <?php

        $folder = 'test/';
        $filetype = '*';    
        $files = glob($folder.$filetype);    
        $total = count($files);    
        $per_page = 12;    
        $last_page = ceil($total / $per_page);  

        if (strpos($last_page, '.') !== false) {
        $last_page = $last_page;
        }

        if(isset($_GET["page"])  && ($_GET["page"] <=$last_page) && ($_GET["page"] > '0') ){
            $page = $_GET["page"];
            $offset = $per_page*($page - 1);      
        }else{
            $page=1;
            $offset=0;      
        }    
        $max = $offset + $per_page;    
        if($max>$total){
            $max = $total;
        }

            show_pagination($page, $last_page);    

            for($i = $offset; $i< $max; $i++){
             $file = $files[$i];
        $path_parts = pathinfo($file);
        $filename = $path_parts['filename'];        
        echo '        
        <div class="galleryCellHolder">
            <div class="galleryCell">
                <a class="fancybox" rel="group" href="'.$file.'"><img class="galleryPhoto" src="'.$file.'" alt="'.$filename.'"></a>
            </div>
        </div>        
        ';          
}

        function show_pagination($current_page, $last_page){
        echo '<div><p>';
            if( $current_page > 1 ){
                echo '<a href="?page='.($current_page-1).'">Anterior</a>';
            }
            echo '&nbsp;&nbsp;&nbsp;&nbsp;';
            if( $current_page < $last_page ){
                echo '<a href="?page='.($current_page+1).'">Próximo</a>';  
            }
            echo '</div></p>';

        }

        echo '<p>'.show_pagination($page, $last_page).'</p>';

        echo "<b>Página $page de $last_page</b>";

        ?>
    
asked by anonymous 14.07.2016 / 00:10

1 answer

0

I've already figured out .... I use reverse mode;)

$ files = array_reverse (glob ($ folder. $ filetype));

    
14.07.2016 / 04:07