Ado.Blogs
Есть вот у меня класс один, может сойдет, я его юзаю местами, правда рандом только.
/*
AUTOMATIC IMAGE ROTATOR
Date - Jan 14, 2005
ABOUT
This PHP script will randomly select an image file from a
folder of images on your webserver. You can then link to it
as you would any standard image file and you'll see a random
image each time you reload.
When you want to add or remove images from the rotation-pool,
just add or remove them from the image rotation folder.
INSTRUCTIONS
1. Modify the $folder setting in the configuration section below.
2. Add image types if needed (most users can ignore that part).
3. Upload this file (imageRotator.inc.php) to your webserver.
That's it, you're done.
*/
Class ImageRotator
{
var $imageDir;
var $files_arr;
/*
/ @Params imageDir : Directory name where images are.
*/
function ImageRotator($imageDir="")
{
$this->imageDir=$imageDir;
$this->files_arr=$this->get_all_files($this->imageDir,"gif,jpg,jpeg",false);
}
function setDirectory($imageDir="")
{
$this->imageDir=$imageDir;
}
function get_all_files($parent_dir="",$file_type="",$include_sub_dir=true)
{
static $file_arr=array();
if (is_dir($parent_dir))
{
$sls="";
$file_type=strtolower($file_type);
if(trim($parent_dir)!="/")
$sls="/";
if ($dh = opendir($parent_dir))
{
while (($file = readdir($dh)) !== false)
{
if(is_dir($parent_dir.$sls.$file) && $file!="." && $file!=".." && $include_sub_dir)
{
$sub_dir=get_all_files($parent_dir.$sls.$file,$file_type);
}
elseif(is_file($parent_dir.$sls.$file)&& $file!="." && $file!="..")
{
$path_parts = pathinfo($file);
$ext=$path_parts["extension"];
if(!isset($ext)|| trim($ext)=="")
$ext="12356";
if(strstr($file_type,strtolower($ext))||$file_type=="")
array_push($file_arr,$parent_dir.$sls.$file);
}
}
closedir($dh);
}
arsort($file_arr);
return $file_arr;
}
return 0;
}
function getRandomImage()
{
return $this->files_arr[rand(0,count($this->files_arr)-1)];
}
}
?>
<?php
require("imageRotator.inc.php");
$rot=new ImageRotator("images");
/*
OR
$rot=new ImageRotator;
$rot->setDirectory("images");
*/
///Functiuon ImageRotator::getRandomImage() will get the image file name randomly.
?>
<img src='<?=$rot->getRandomImage();?>'>