All pastes #177827 Raw Edit

Unnamed

public php v1 · immutable
#177827 ·published 2006-09-20 18:59 UTC
rendered paste body
<?php// print a random image.  Don't forget ending slash!// setting $type to 'all' will return all images.$result =  getRandomImage('./logos/');print $result["html"];print "the file name is: " . $result["filename"];function getRandomImage($dir,$type='random'){global $errors;  if (is_dir($dir)) {  $fd = opendir($dir);  $images = array();      while (($part = @readdir($fd)) == true) {      clearstatcache();          if ( eregi("(gif|jpg|png|jpeg)$",$part) ) {              $images[] = $part;          }      }    // adding this in case you want to return the image array    if ($type == 'all') { return $images; }    // Be sure to call srand() once per script    srand ((double) microtime() * 1000000);    $key = rand (0,sizeof($images)-1);    $output = array();    $output["html"] = "<img src=\"" . $dir . $images[$key] . "\" width=\"647\" height=\"193\" \/>";    $output["filename"] = $images[$key];    return $output;  } else {      $errors[] = $dir.' is not a directory';      return false;  }}?>