I'm trying to pick out a single result from an array at random and use it to display a photo for each photo album.
This is the code so far:
$max_cols = 4;
$fileCount = 0;
$output = '';
$dir = "pictures";
$folder = scandir($dir, 0);
$files = array_reverse($folder);
for( $ctr = 0; $ctr < sizeof( $files ); $ctr++ ) {
if($files[$ctr] != "." && $files[$ctr] != "..")
if (sscanf($files[$ctr], '%4d%2d%2d', $year, $month, $day) == 3) {
$months = array(1 => 'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December');
$date = "$day $months[$month] $year";
$fileCount++;
if($fileCount%$max_cols==1)
{
$output .= "<tr>\n";
}
$link = "$dir/$files[$ctr]";
// echo $link;
$curDir = getcwd();
if(chdir($link))
{
$dirpic = glob('*.{JPG,jpg}', GLOB_BRACE);
sort($dirpic);
chdir($curDir);
// echo $dirpic;
$key = array_rand($dirpic, 1);
echo $dirpic[$key[0]];
$output .= "<td align=center><a href='list_pictures.php?pics=$dir/$files[$ctr]'><img src='$link/$dirpic' style='height:100;width:auto;'><br>$date</a></td>";
if($fileCount%$max_cols==0)
{
$output .= "</tr>\n";
}
}
}
}
print "
<table border=\"0\" cellpadding=\"\"0 cellspacing=\"4\" bgcolor=\"#000000\">
{$output}
</table>
";
Array_Rand still only seems to throw up an array... struggling to get it to pick one result. Any ideas please?