Need Help Finding Random Image On Server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Need Help Finding Random Image On Server

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Please explain the differences between a "normal random image" script and what you're looking for in more detail.
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Post 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)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

get the directory listing into an array, then pick a random number between 0 and the array length -1
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

...or just use array_rand() ;)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

feyd wrote:...or just use array_rand() ;)
:banghead: :bow:
Post Reply