OK let's see if I get this? You want to load in the image file names into an array and then retrieve it randomly?
First don't store any info you don't need, filter out the files before storing them.
Second using $names[count($names)] is the same as $names[]
Finally, you forgot to put the file paths in with the image names.
<?
$folder=opendir("rndimgs/");
while ($file = readdir($folder)){
$ext=strtolower(substr($file,-4));
if ($ext==".jpg"||$ext==".gif"||$ext==".jpeg"||$ext==".png"){
$names[] = $file;
}
}
closedir($folder);
sort($names);
srand ((double) microtime() * 10000000);
$rand_key = array_rand ($names);
$slika=$names[$rand_key];
$dimensions = GetImageSize($slika);
if (isset($pic)){
header ("Location: rndimgs/$slika");
}
else {echo "<img src=\"rndimgs/$slika\" $dimensions[3]>";
}
?>