|
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]
|