neur0maniak <us****@neur0maniak.co.uk> wrote in news:41830267$0$43631
$e*******@ptn-nntp-reader04.plus.net:
You probably find it safer to keep doing it the way you are.
Or instead modify it to build an array containing filenames and then
randomly pick an entry from the array. This is to account for if a file
is ever removed, no errors would occur.
Try this, as described above. Forget where I found the code but it works
just fine. $dirpath should be a fullpath to the appropriate directory and
requires a slash at the end... or you can add it to the couple of lines
in between the path and the image filename. Everything in the directory
except those in the if statement will be put into the array.
$dir_contents = array();
$d = dir($dirpath);
while ( $crnt_file = $d->read() ) {
if ($crnt_file == "." || $crnt_file == ".."
|| is_dir($dirpath.crnt_file))
continue;
$dir_contents[] = $dirpath.$crnt_file;
}
$d->close();