Do you have a question? Post it now! No Registration Necessary. Now with pictures!
February 16, 2012, 5:38 pm
rate this thread
been attempting it on wampserver but I have three different jpegs in a
row on the LHS and I am trying to implement a random image selector so
that each time a page is loaded you get three new and different images.
I have tried a couple of scripts for random images but they both
produced three times the same image each time the page was loaded.
Anyone know a script which will work?
Re: php random image selection
It's not that difficult to roll your own:
1) get the names of all the files in directory x that match any of *.gif,
*.jpg, *.png. Look up the php documentation for glob()
2) pick 3 at random. Look up the php documentation for array_rand()
3) display them in the html. Use echo.
Some string manipulation may be required. Glob() uses the filesystem
path. You might want to apply the basename() function to the three random
picks, and then prepend them with the path relevant to the webroot.
eg: url0 = "http://www.example.com/images /" . basename($files[$keys]);
These are the bits that you need to glue together, have fun with your
construction kit toy. ;)
- » ssh on command line: force using a group size (prime size) of 1024 (and no...
- — The site's Newest Thread. Posted in » Secure Shell Forum