Random Image & Directory images

Discussion in 'PHP' started by tong1991, Apr 8, 2009.

  1. #1
    Hello, How would i make a random image be chosen from a directory of images, and is there a way to show all of the images, Like a thumbnail, But it shows all the images in a certain directory?

    thanks
     
    tong1991, Apr 8, 2009 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    first use php.net/glob for reading all files in the current directory and add them into an php.net/array, after creating this array do a php.net/rand(0, php.net/count(array)) and get a random number. Now you can fetch the image file and display it to the user

    See this example
    http://www.phpjunkyard.com/random-image.php
     
    EricBruggema, Apr 15, 2009 IP