This is an example of a short script that reads a file with
names of images, separated by a newline. It returns a random image.
inherit "spiderlib"; // Has some nice functions, as for
// example, http_direct
array (string)files; // An array of strings, with the image filenames
#define FILELIST "/the/full/path/to/the/filelist"
// Absolute path to the image list.
#define BASEDIR "/"
// The path to be prepended to the filenames in
// the list
/* Create is called when the script is loaded.
Here we read the file from the disk and explode it into an array
*/
void create()
{
files = read_bytes(FILELIST)/"\n";
}
/* Don't reload the module from file, unless the creator want to.
(Call the script with '/random.ulpc?reload=whatever', to reload it.)
*/
int no_reload(object id)
{
if(!id->variables->reload)
return 1;
return 0;
}
/* This function is called every time someone goes to the URL of the
script.
*/
mapping parse(object id)
{
return http_redirect(BASEDIR+files[random(sizeof(files)));
// Return a random file
}