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";

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.