<?php

/*

Get a random image and display it.

By Simon Carr - me@simoncarr.com

So damn simple it's totally free. 

*/

function p_graphic($folder) { // random graphics
                                      // It's the goofy cartoon pic mostly
    
$filelist parse_dirlisting($folder);
    
$image_URL pick_image($filelist,$folder);
    return(
$image_URL);
}


function 
pick_image($filelist,$folder) {
    
srand ((double) microtime() * 10000000); // Caution for caution's sake.
    
$random_image array_rand($filelist,1);
    
$random_pic_URL "/$folder/$filelist[$random_image]";
    return(
$random_pic_URL);
}

function 
parse_dirlisting($folder) {
    
$handle=opendir($folder);
    
$i 0;
    while (
false!==($file readdir($handle))) {
        if (
$file != "." && $file != ".." && !ereg("~",$file) && !ereg("^\..",$file)) {
            
$filelist[$i] = $file;
            
$i++;
        }
    }
    
closedir($handle);
    if(!
$filelist) {
    
$filelist[0] = "null";
    
$filelist[1] = "value";
    }
    return(
$filelist);
}

?>

<IMG src="<?php print p_graphic("graphics.random"); ?>">