Action: Random Image
{{randomimage imgpath="files/"}}
/actions/randomimage.php
<?php
# $path="files/";
# $path="files/perpage/";
$path="$imgpath";
if (!$path)
echo "<i>Please specify a path with the parameter imgpath, e.g. {{randomimage imgpath=\"files/\"}}.</i><br />";
else
{
$folder=opendir($path);
while ($file = readdir($folder))
$names[count($names)] = $file;
closedir($folder);
sort($names);
$tempvar=0;
for ($i=0;$names[$i];$i++)
{
$ext=strtolower(substr($names[$i],-4));
if ($ext==".jpg"||$ext==".gif"||$ext=="jpeg"||$ext==".png"){$names1[$tempvar]=$names[$i];$tempvar++;}
}
srand ((double) microtime() * 10000000);
$rand_keys = array_rand ($names1, 2);
$xmImg=$path.$names1[$rand_keys[0]];
$dimensions = GetImageSize($xmImg);
if (isset($pic)){header ("Location: $xmImg");}
else {echo "<img src=\"$xmImg\" $dimensions[3]>";}
}
?>
To Do
- not ready yet
- any ideas?
- alt text, show image name
- (?) if used only in wacko folders check acls
- limit path – config inside action