html5 - Randomly Generate Multiple Files From Directory with PHP -
i building website people can go , upload images, gifs, , videos. on home page, want list files @ random upload directory.
<article class="item thumb" data-width="384"> <h2><?php echo $file_title;?></h2> <a href="<?php echo $randomimage ?>"><img src="<?php echo $randomimage ?>" alt=""></a> </article> <article class="item thumb" data-width="274"> <h2><?php echo $file_title;?></h2> <a href="<?php echo $randomimage ?>"><img src="<?php echo $randomimage ?>" alt=""></a> </article>
and total of 5 times. $randomimage generated code:
<?php $imagesdir = 'uploads/'; $images = glob($imagesdir . '*.{jpg,jpeg,png,gif}', glob_brace); $randomimage = $images[array_rand($images)]; $file_title = $randomimage; ?>
i want able add feature user scrolls down, more , more of these articles containing images show up, each containing random not shown file. how can display files @ random without having manually enter unique variables?
p.s. right not have files stored in database.
remove randomly selected image $images
before select another.
loop 5 images
<?php // files $imagesdir = 'uploads/'; $images = glob($imagesdir . '*.{jpg,jpeg,png,gif}', glob_brace); $imagescount = count($images); for($i = 0 ; $i < $imagescount ; $i++) { // select image $randomindex = array_rand($images); // select image index $file_title = $randomimage = $images[$randomindex]; // use selected image unset($images[$randomindex]); // remove selected image // print_r($images); // can see left in $images // show image ?> <article class="item thumb"> <h2><?php echo $file_title;?></h2> <a href="<?php echo $randomimage ?>"><img src="<?php echo $randomimage ?>" alt=""></a> </article> <?php } ?>
Comments
Post a Comment