#native_company# #native_desc#
#native_cta#

random image picker

By FocusMulti
on February 5, 2003

Version: improved_new

Type: Function

Category: File Management

License: GNU General Public License

Description: Picks a random image from a directory and displays it. Could be modified to do much more and includes directions on its use.

<?php
/*
Authored by the Perpetual Dreamer
http://www.perpetualdreamer.com
*/

//directory here (relative to script)
$path = '.';

$i = 0;
$imgDir = opendir ($path);
	while ( $file = readdir( $imgDir ) )
	{	
		//checks that file is an image
		$file_type = strrchr( $file, "." );
		$is_image = eregi( "jpg|gif",$file_type );
		
		if ( $file != '.' && $file != '..' && $is_image )
		{ $images[$i++] = $file; }
	}
closedir ($imgDir);

srand( (double) microtime()*1000000 );
$image_name = $path . '/' . $images[rand( 0,sizeof( $images ) -1 )];
$imgSize = GetImageSize( $image_name );

//ends script if no images found
if ( $i == 0 )
	die();

print ( "<img src="" . $image_name . """ . $imgSize[3] . " />n" );

/*
Basic code (by alland) available at:
https://phpbuilder.com/snippet/detail.php?type=snippet&id=42
*/
?>