You are here: Re: PHP image rotator ... « All PHP « IT news, forums, messages
Re: PHP image rotator ...

Posted by Koncept on 09/28/54 11:57

In article <wXbKg.1162$Mh7.563@edtnps90>, Rob <bobie@bobb.com> wrote:

> Hi,
>
> I'm a webbie, but new to php.
>
> DL'd a script which is a random image rotator. (below).
> Inserted the path to my images folder, tried it on 2 servers but get error
> on both:

How about something like this? (Defaults to the current directory)

<?php
function findImages($dir=".",$recurse=TRUE,&$a=array()){
if($dh = @opendir($dir)){
while(($item = readdir($dh)) !== false){
if($item != "." && $item != ".." && $item{0} != "."){
if(is_file($curPath=$dir.'/'.$item)){
if(preg_match('/\.(jpe?g|png|gif)$/i',$item))
$a[]=$curPath;
} else {
$recurse && findImages($curPath,$recurse,$a);
}
}
}
closedir($dh);
}
return $a;
}

$dirImages = findImages();
$randImage = $dirImages[array_rand($dirImages,1)];

if(isset($_GET['image'])){
@header("Location: $randImage");
exit;
}

$props = getimagesize($randImage);
echo "<img src=\"$randImage\" {$props[3]} alt=\"A random image\" />\n";
?>

--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация