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
djwk
Forum Commoner
Posts: 56 Joined: Tue Mar 07, 2006 2:14 pm
Post
by djwk » Mon Jan 22, 2007 4:03 am
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
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Jan 22, 2007 4:20 am
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 » Mon Jan 22, 2007 4:49 am
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)
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Mon Jan 22, 2007 11:57 am
get the directory listing into an array, then pick a random number between 0 and the array length -1
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jan 22, 2007 12:03 pm
...or just use
array_rand()