Hi guys. I'm a keen photographer and have hundreds of good photos. I want to build a very simple site that will just have my logo at the top a little bit of text then I want a picture. Here's the tricky part. I want to upload my hundreds of photos onto my server then I want a script that will select on of those pictures at random then display that image on the homepage. So each time the user refreshes it will pick a completely random picture again. Please could someone tell me the code for how to do this! Many Thanks
Put all the images in a folder. Save this as randomImage.php and place in the same folder as images. On site, <img src="folder-of-images/randomImage.php" alt="" /> This is probably the simplest way, if you don't want to name each image a number then use rand().'.jpg'; or whatever.
Hi, I'm using jQuery, I do a div where I display images within as background images I give my images names ending with numbers from 0 to x-amount of pics and use something like this to generate random image within that div: (with a bit of fading in effect) $(document).ready(function(){ var totalNum = 5; //the total number of images in a folder. var rndNum = Math.floor(Math.random() * totalNum); $("div#loader").hide(10) $("div#loader").css("background-image","url(_images/dental_implants" + rndNum + ".jpg)"); $("div#loader").fadeIn(1500); }); Code (markup):
http://www.alistapart.com/articles/randomizer/ Everything you need about automatic image rotation everytime a page loads & more.