function randImg($dir,$width,$height,$at=array(),$extensions=array(‘jpg’,’jpeg’,’png’,’bmp’)) {
if (is_dir($dir)) {
$opendir = opendir($dir);
while ($result = readdir($opendir)) {
if (!is_dir($result)) {
$info = pathinfo($result);
$ext = $info[‘extension’];
if (in_array($ext,$extensions)) {
$at[] = $result;
}
}
}
$rand = $at[rand(1,count($at)-1)];
echo ‘
‘;
} else {
die(‘dir not found’);
}
}
Kullanımı:
randImg(‘forum/avatars’,150,150);