<!-- SophiaKnows -->

PHP: RANDOM IMAGE
Rev 3: December 2004


<?php
/* --------------------------------- */
/*     SOPHIAKNOWS: PHP LIBRARY      */
/* --------------------------------- */
/*          RANDOM IMAGE             */
/* --------------------------------- */
/*  Created:  2003-01-01             */
/*  Issued:   2003-01-01             */
/*  Modified: 2004-12-30             */
/*  Component: PHP RANDOM IMAGE      */
/*  Copyright (c) 2003-2004          */
/*  Tony Pisarra, SophiaKnows        */
/* --------------------------------- */
/* --------------------------------- */


// 1. SET DIRECTORY

$the_dir="images/";

// 2. GET FILE SRC LIST

if (is_dir($the_dir)) {
   if ($dh = @opendir($the_dir)) {
       while (($file = readdir($dh)) !== false) {
        if(preg_match("/\.[jgp][pin]e?[gf]$/i",$file)){
        	$random_src[]= $the_dir.$file;
        	}
       }
       closedir($dh);
   }
}

// 3. SELECT RANDOM

function ReturnRandomSource(){
	global $random_src;
	return $random_src[rand(0,(count($random_src)-1))];
	}

?>
<title>PHP Page</title>

<body links=#000077 vlink=#333337>

<p align=center>

<!-- PHP: PRINT RANDOM IMG SRC -->
<img src="<?php echo(ReturnRandomSource()) ?>" />

</p>

</body>


< CODEBASE | TOP^ | MAINPAGE >

Text & Design By Tony Pisarra
© SophiaKnows 1998-2004