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