Multiple Random Image PHP Script

dice

Recently, while developing a site, I ran into a need for the ability to select 4 random  images from a folder and display them in a div container. I searched around and found several scripts that would pull single random images (I’ve used this simple script from Matt Mullenweg’s site several times, for example) but nothing that would randomize multiple images. As I often do when I run into a brick wall, I tweeted about my problem and received a response from James Paden of Xemion.com* offering to write the script for me for free!  The kindness and generosity of people I have met through blogging and Twitter continually amazes me.

He based the multi-image script on this single random image script, and it works great! Since I had such a hard time finding one I thought (with James’ permission) that I would make it available here. It’s set up to call 4 images, but shouldn’t be too hard to tweak for the number you need.

Click here for a demo.

Click here to get the code and instructions.

Thanks again to James for helping me out!

*Xemion.com is a great resource for small business owners and managers to both find web designers and learn how to best hire and work with design firms.

[Post to Twitter]  [Post to Delicious]  [Post to Digg]  [Post to StumbleUpon] 

You might also enjoy:

13 Responses

  1. JamesM says:

    A nice implementation, but as ever with PHP there’s about a hundred different ways to do it. That in itself can be confusing, but if you’ve got the time it’s well worth learning the basics. I’ve developed using PHP for nearly five years, but I still come across things I’ve never seen before!

  2. maca says:

    very useful script! great post
    thank you for sharing

  3. Karlyn says:

    Useful and much appreciated for sharing.
    Thanks Randa and James!

  4. Keegan says:

    I can already think of a couple of places this script will come in handy. Thanks for finding it and posting!

  5. Frank Jovine says:

    I used a script like this on a fishing site I once owned. It makes the page look fresh by serving up a different image each time the page is loaded.

  6. Palinka says:

    Great script, just what I needed. Thx for sharing.

  7. Dee says:

    Being a non-geek my eyes usually glaze over when I see letters like php and words like div container. The demo made all the difference however.

    It is certainly cool and gets even a blogger with no computer background like me to really want to try it.

  8. Mo says:

    I can see using a code like this for making a spash screen for your site.

  9. Covek Bez says:

    It’s an easy database pull. That’s what PHP is for. I’m not to savvy when it comes to writing scripts, so any little bit would help. Anyways, I’ve been working on a new project for a feed for images. This script will definitely be a good source-view for breaking down the code and messing with it.

  10. Sam Logan says:

    Great srcipt Randa, it was very kind of James to write it for free! Thanks for sharing it with us.

  11. mike says:

    great post. thanks for sharing Randa

  12. Shaun says:

    Hi Randa, thanks for sharing the info with us. I’m new to PHP and I’m looking to implement this into my own website. The single random image script might just work for what I want.

  13. The PHP Script is great. I have seen a WordPress Theme which have a header at top and the image change at every page load. Now I know, it is possible through some php coding like the one shown here.

    Great helping post. I have saved the txt code with myself for use in future :)

    Client Quotes

    Randa made my simple concept and basic mockup into a work of art! Randa’s sense of style, attention to minutia, and conscientiousness made her the perfect person for my blog development. ~Brandon Clay


    Recent Work

    I recommend



    My Other Sites