Zend - The PHP Company




Graphics

Add Code


Random image from a directory  

Type: code fragment
Added by: mattr
Entered: 19/07/2000
Last modified: 02/12/2004
Rating: - (fewer than 3 votes)
Views: 6576
Generates a random image link from an image directory.


<?
  $handle   
opendir"path/to/image/dir" );
  
$imgArray = array( );

  while( 
$file readdir$handle ) ) {
    if( 
$file != "." && $file != ".." ) {
      
array_push$imgArray$file );
    }
  }
  
closedir$handle );

  
mt_srand( (double)microtime( ) * 1000000 );
  
$randval mt_rand0sizeof$imgArray ) - ); 
  print( 
"<IMG SRC="img/" . $imgArray[ $randval ] . "">" );
?>


Usage Example




Rate This Script





Search



This Category All Categories