That will definetely not work... See here: http://forums.invisionpower.com/index.php?...13& This code should work: <?php $dh = opendir("."); while (false !== ($file = readdir($dh))) { if (preg_match('/\.jpg$/i', $file) and $file != "avatar.png") // scanning for .jpg files only and stopping avatar.jpg being loaded (you will run into errors if this isnt here) { $filelist[] = $file; } } srand((double)microtime()*1000000); $picnum = rand(0, sizeof($filelist) - 1); header("Location: " . $filelist[$picnum]); closedir($dh); ?> Just replace the .jpg with the file extension you need to use. Leave avatar.png as is, and name the file avatar.png. Put all your images in one directory!