Project

General

Profile

1
//:Get a random image from a folder in the MEDIA folder.
2
//:Commandline to use: [[RandomImage?dir=subfolder_in_mediafolder]]
3
$dir = ( (isset($dir) && ($dir!='') ) ? $dir : '');
4
$folder=opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$dir.'/.');
5
$names = array();
6
while ($file = readdir($folder))  {
7
$ext=strtolower(substr($file,-4));
8
if ($ext==".jpg"||$ext==".gif"||$ext==".png"){
9
$names[count($names)] = $file;
10
}
11
}
12
closedir($folder);
13
shuffle($names);
14
$image=$names[0];
15
$name=substr($image,0,-4);
16
return '<img src="'.WB_URL.MEDIA_DIRECTORY.'/'.$dir.'/'.$image.'" alt="'.$name.'" width="95%" />';
(9-9/17)