html - PHP - Random Image from folder, next, random and previous image -
i'am new php , have tried browse forums reply not find looking for. here go.
so want basic image grabber gets unique image folder , echo/printing out on website, in additional of have next image button, previous button , random image button.
this how far have come.
here have example of mean. (yes basic i'am trying learn)
<?php $dir = "images"; $images = scandir($dir); $z = rand(2, sizeof($images)-1); ?>
this code above "generates" random image not unique every time, illustration if refresh page have possibility same pic several times. <- help here nice unique image every time come in page, or not entering more when pressing random button, getting farther down.
<div class="container"> <!-- start rng image --> <center><div class="col-md-8 col-md-offset-2"> <img src="images/<?php echo $images[$z]; ?>" alt="sorry image on vacation" class="thumbnail img-responsive"> </div></center> <!-- close rng image -->
the code above front end end code displaying random image.
my biggest problem have understand how can next,previous random array in buttons.
<div class="navbar navbar-inverse"> <!-- start navbar --> <div class="navbar-inner"> <center><div class="btn-group"> <button type="button" class="btn btn-lg btn-danger>"previous</button> <button type="button" class="btn btn-lg btn-info">random</button> <button type="button" class="btn btn-lg btn-success">next pic</button> </div></center> </div> </div> <!-- close navbar -->
in order prepare duplicate image problem, add together cookie (session do), storing lastly few(5) images user has seen. before choosing image show, remove 5 images stored in cookie.
as far buttons go, seek looking ajax.
php html image twitter-bootstrap random
No comments:
Post a Comment