Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <?php $imglist='';
  2. //$img_folder is the variable that holds the path to the banner images.
  3. // see that you dont forget about the "/" at the end
  4. $img_folder = "images/";
  5. mt_srand((double)microtime()*1000);
  6. //use the directory class
  7. $imgs = dir($img_folder);
  8. //read all files from the directory, checks if are images and ads them to a list (see below how to display flash banners)
  9. while ($file = $imgs->read()) {
  10. if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
  11. $imglist .= "$file ";
  12. } closedir($imgs->handle);
  13. //put all images into an array
  14. $imglist = explode(" ", $imglist); $no = sizeof($imglist)-2;
  15. //generate a random number between 0 and the number of images
  16. $random = mt_rand(0, $no); $image = $imglist[$random];
  17. //display image
  18. echo '<img class="img-responsive" src="'.$img_folder.$image.'" border=0>'; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement