Jump to content

Simple image gallery reading from directory - random / numerical placement


phatmambo

Recommended Posts

I have a very simple piece of code to create a grid based gallery. The thumbnails are loaded from a single directory and are name 1.jpg... 2.jpg... 3.jpg etc

 

At the moment the images appear to be loaded in randomly. I want them to load in numerically in terms of their filename. I know I may need to use 'sort' or 'natsort' but where in the code?

 

Thanks for any help you can give me

 

 <?

$images = "Images/Bag Thumbs/"; # Location of small versions

$big    = "ruxxwomens.php?id="; # Location of big versions (assumed to be a subdir of above)

$cols   = 4; # Number of columns to display

if ($handle = opendir($images)) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != ".." && $file != rtrim($big,"/")) {
          $files[] = $file;
       }
   }
   closedir($handle);
}



$colCtr = 0;
echo '<table width="800" cellspacing="0" cellpadding="0" border="0"><tr>';
foreach($files as $file)
{
  if($colCtr %$cols == 0)

    echo '</tr><tr>';

  echo '<td align="center"><a href="' . $big . $file . '"><img src="' . $images . $file . '" cellspacing="0" cellpadding="0" border="0"></a></td>';

  $colCtr++;
}
echo '</table>' . "\r\n";

?>

put here

 

if ($handle = opendir($images)) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != ".." && $file != rtrim($big,"/")) {
          $files[] = $file;
       }
   }
sort($files);
closedir($handle);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.