All pastes #191364 Raw Edit

julie -- php

public text v1 · immutable
·published 2006-10-04 22:11 UTC
rendered paste body
!-- Wallpapers.php -->
<?php

$rows = 4;
$cols = 6;

$image_dir = '../images/wallpapers/';
if (!($dh = opendir($image_dir)))
{
   die ("Cound not open $image_dir");
}

$files = array();
$count = 0;
while ($file = readdir($dh))
{
   if (is_dir($image_dir . $file))
   {
      continue;
   }
   if (file_exists($image_dir . "/$file"))
   {
      $files[] = $file;
   }
}

if (($rows * $cols) > count($files))
{
   $row = $cols = floor(sqrt(count($files)));
}

$rand_indx = array_rand($files, $rows * $cols);

print "<table>";

for ($i = 0; $i < $rows; $i++)
{
   print "\t<tr>\n";
   for($y = 0; $y < $cols; $y++)
   {
      $image = $files[$rand_indx[$count++]];
      print "\t\t<td> <a href=images/wallpapers/$image><img src=images/wallpapers/$image></a> </td>\n";
   }
   print "</tr>\n";
}
print "<table>";
?>