samedi 10 juin 2017

PHP Random Images, not repeating

Look at this url:
http://ift.tt/2rXYOB0
I need those images to be random, not repeating, per album.
Can anybody help me on this?
......................................................................

Here is the code:

if (!isset($_GET['album'])) {
    // display list of albums
    $folders = scandir($mainFolder, 0);
    $ignore  = array('.', '..', 'thumbs');
    $albums = array();
    $captions = array();
    $random_pics = array();
    foreach($folders as $album) {
        if(!in_array($album, $ignore)) {
            array_push( $albums, $album );
            $caption = substr($album,0,40);
            array_push( $captions, $caption );
            $rand_dirs = glob($mainFolder.'/'.$album.'/thumbs/*.*', GLOB_NOSORT);
            $rand_pic = $rand_dirs[array_rand($rand_dirs)];
            array_push( $random_pics, $rand_pic );
        }
    }
    if( count($albums) == 0 ) {
        echo 'Não há álbuns.';
    } else {
        $numPages = ceil( count($albums) / $albumsPerPage );
        if(isset($_GET['p'])) {
            $currentPage = $_GET['p'];
            if($currentPage > $numPages) {
                $currentPage = $numPages;
            }
        } else {
            $currentPage=1;
        }
        $start = ( $currentPage * $albumsPerPage ) - $albumsPerPage;
        for( $i=$start; $i<$start + $albumsPerPage; $i++ ) {
            if( isset($albums[$i]) ) {
                echo '<div class="thumb-album shadow" style="width:100%; text-align:center;">
                        <div class="thumb-wrapper">
                            <a href="'.$_SERVER['PHP_SELF'].'?album='. urlencode($albums[$i]) .'" style="padding:5px;">
                                <img src="'. $random_pics[$i] .'" width="'.$thumb_width.'" alt="" />
                                <img src="'. $random_pics[$i] .'" width="'.$thumb_width.'" alt="" />
                                <img src="'. $random_pics[$i] .'" width="'.$thumb_width.'" alt="" />
                                <img src="'. $random_pics[$i] .'" width="'.$thumb_width.'" alt="" />
                                <img src="'. $random_pics[$i] .'" width="'.$thumb_width.'" alt="" />
                                <img src="'. $random_pics[$i] .'" width="'.$thumb_width.'" alt="" />
                            </a>
                        </div>
                        <a href="'.$_SERVER['PHP_SELF'].'?album='. urlencode($albums[$i]) .'">
                            <span>'. $captions[$i] .'</span>
                        </a>
                    </div>
                    <div class="clear"></div>';
            }
        }
        echo '<div class="clear"></div>';
        echo '<div align="center" class="paginate-wrapper">';
            $urlVars = "";
            print_pagination($numPages,$urlVars,$currentPage);
        echo '</div>';
    }




Aucun commentaire:

Enregistrer un commentaire