Using a random image from a directory

Here's a way to get an image chosen at random from a directory of images on a web server.

With this, you can change what's being displayed simply by adding images to or removing them from the directory. It uses PHP, so you'll need to have that enabled on your web server if it isn't already. It's a very simple script that just picks a random file (one with an image extension) from its own directory and returns it.

Here's the script: index-php.php.txt.

  • Save that as simple index.php on the server.
  • Then put a couple of images in the same directory. Point your web browser at index.php - often you can just point it at the URL which refers to the directory, because index.php will be a default index file - and you should get to see one of the images. Reload a few times, and you should get to see the others.
  • Now you can create an image entry in CODA which points to the same URL. It might be worth ticking the 'Webcam image' option to warn CODA not to cache this because it may change each time.
  • Finally, put the image entry into a CODA album - then you can specify its duration to choose how frequently it should be reloaded.

My PHP is very rusty, so you may want to tweak the script to improve it, or modify it to suit your needs, but it works for me!