Page 1 of 1

Need Help Finding Random Image On Server

Posted: Mon Jan 22, 2007 4:03 am
by djwk
Hi there.

I need a piece of code to check the directory "pics" and return a random full URL path of the random picture selected instead of echoing the picture like normal random image scripts.

IE: "http://www.example.com/pics/blah.jpg"


Can anyone help?


Thanks,
Alex

Posted: Mon Jan 22, 2007 4:20 am
by volka
Please explain the differences between a "normal random image" script and what you're looking for in more detail.

Posted: Mon Jan 22, 2007 4:49 am
by djwk
Basically a normal random image script echos the actual image like this "<img src=random.php>" on the page you want it.

I just want a script to pick a random file in a directory and put the full URL of the image into the variable "$image" (As shown in my IE above)

Posted: Mon Jan 22, 2007 11:57 am
by Kieran Huggins
get the directory listing into an array, then pick a random number between 0 and the array length -1

Posted: Mon Jan 22, 2007 12:03 pm
by feyd
...or just use array_rand() ;)

Posted: Mon Jan 22, 2007 12:20 pm
by Kieran Huggins
feyd wrote:...or just use array_rand() ;)
:banghead: :bow: