• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Image script question

striker

Strike 3
NLC
OK You know the scripts that show something in a .png file or .jpg file (i.e. www.danasoft.com sigs) ??

Is there a script that will load a random image from a directory (i.e. www.striker.com/randomimgdir/) into a .jpg file???

Thanks for your help and time I hope you understood the question if not let me know and I will try to be more clear.
 
PHP:
<?php
function randimg()
{
$path = "/home/uname/public_html/path_to_img"; // full path to files on server

$handle = @opendir($path);
if($handle < 0)
 exit;
$count = 0;
$files = array();
while(($file = @readdir($handle)) !== false) {
 if($file != "." && $file != "..") {
  if(substr($file, 0, 1) == ".")
   continue;
  if(@is_dir("$path/$file"))
   continue;

  $lastdot = strrpos($file, ".");
  $ext = strtolower(substr($file, $lastdot+1));

  if(!($ext == "jpeg"))
   continue;
  if(!($ext == "gif"))
   continue;
  if(!($ext == "png"))
   continue;
  $files[$count++] = $file;
 }
}
@closedir($handle);

return $files[rand(0, $count)];
}
?>

Then this were you want the list

PHP:
<a href="directory/<?=randimg()?>"><?=randswf()?></a>

It should work, but i dunno about this small bit;

PHP:
  if(!($ext == "jpeg"))
   continue;
  if(!($ext == "gif"))
   continue;
  if(!($ext == "png"))
   continue;

Robert.
 
Back
Top