PHP - Random Image


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. //total number of images
  3. $totalimages = "300";
  4. //file type
  5. $file_type = ".jpg";
  6. //location
  7. $image_folder = "../assets/images/";
  8. //start counting from number
  9. $startcounter = "1";
  10. $random = mt_rand($startcounter, $totalimages);
  11. $image_name = $image_folder . $random . $file_type;
  12. ?>
  13. <img src="<?php echo $image_name; ?>" name="image<?php echo $random; ?>" width="" height="" border="0" id="image<?php echo $random; ?>" alt="" />

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.