1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
/*
*
* randomfile.pike
* returns a random file from those in directory DIR
*
* This code is (C) 1999 Bill Welliver <hww3@riverweb.com>
* It can be freely distributed and copied under the terms of the
* GNU General Public License.
* This code comes with NO WARRANTY of any kind, either implicit or explicit.
*
* instructions for use:
* 1. edit DIR to point to a directory of files you'd like the script to
* return.
* 2. populate DIR with said random files.
* 3. either a) insert randomfile as a link or image src, or b) use the
* RXML <insert> tag to have the contents of the random file inserted
* in your web page.
*
*/
inherit "roxenlib";
#define DIR "/PATH/TO/RANDOM/FILES/"
mixed parse(object id){
string data;
array d=get_dir(DIR);
string filename=DIR + d[random(sizeof(d))];
data=Stdio.read_file(filename);
return http_string_answer(data, id->conf->type_from_filename(filename));
}
|