This should be easy for you guys but I don't even know where to start:
I've got a folder that I add and subtract html files from. At any point, when the user submits a form, I want to exit to a random html file in that folder. How do I select the file randomly?
selecting random files
Moderator: General Moderators
glob() and array_rand() maybe?
Code: Select all
$dir=opendir($picture_path);
$i=0;
while($imgfile=readdir($dir))
{
if ($imgfile != "." && $imgfile!="..")
{
$imgarray[$i]=$imgfile;
$i++;
}
}
closedir($dir);
$rand=rand(0,count($imgarray)-1);
if($rand >= 0)
{
$file = $imgarray[$rand];
}