the last time i looked for it, i couldn't find the original source where i found this JavaScript which its Author named "Alpharead 3". i commented the source, but couldn't find it now some 4 months later.
anyway-- i use that, and this PHP script which, if i recall correctly, was also inspired by the Alpharead author. i might be mixing it up w/ something else though. if anyone is concerned, i will do my best to dig through my notes. i wrote some of it too, so it's difficult to tell what's what, where it's original, etc. i hope you understand. thanks.
here's the code:
<?php
/* alpharead version 3: This function returns an array containing the names of the files inside any given folder, excluding files that start with a '.', as well as the filenames listed in the '$killit' array. This array is sorted using the 'natural alphabetical' sorting manner. If no input is given to the function, it lists items in the script's interpreted folder. Version 3 fixes a MAJOR bug in version 2 which corrupted certain arrays with greater than 5 keys and one of the supposedly removed filenames.
written by Admiral at NuclearPixel.com */
function alpharead3($dir){
if(!$dir){$dir = '.';}
foreach(glob("$dir/*") as $item){$sort[]= end(explode('/',$item));}
$killit = array('index.html', 'index.php', 'thumbs.db', 'styles.css');
$killcounter = 0;
foreach($sort as $sorteditem){
foreach($killit as $killcheck){
if(strtolower($sorteditem) == strtolower($killcheck))
{unset($sort[$killcounter]);}
}$killcounter++;}
if($sort){natsort($sort);}
foreach($sort as $item){$return[]= $item;}
if(!$return){return array();}
return $return;
}
//some basic usage of glob() to download images
$filelist = "<table><tr><th> 2005:</th></tr>
<tr>";
$y=1;
$folder = 'images/gallery';
$pics = count(alpharead3($folder));
foreach(alpharead3($folder) as $item) {
if ($y <= "3") {
$filelist .= '<td style=\"float:right;padding:1em;\">'.$item.'<br /><a href="'.$folder.'/'.$item.'"><img src="'.$folder.'/thumbs/'.$item.'" /></a></td>';
$y++;
} elseif ($y > "3") {
$filelist .= '</tr><tr><td style=\"float:right;padding:1em;\">'.$item.'<br /><a href="'.$folder.'/'.$item.'"><img src="'.$folder.'/thumbs/'.$item.'" /></a></td>';
$y ="1";
}
}
$filelist .= "</table><p>end of list</p>";
?>
the previous version did not have the line after elseif() where i print that final <td> before setting $y back to "1", so in the previous version (you can view if you click -- you need to click gallery there cause my javascript will size the window properly-- i need to have onload() instead of onclick() to fix that, right?) it was missing every 4th image. the version above gets them all, but then i have an empty <img src" " > tag at the end, and i don't really want 4 thumbs per row because my CSS is setup for 3 thumbs per row.
any advice? maybe you know of something completely different somewhere that i might want to try? is this super-sloppy, or am i "on the right track" here?
what i want are 3 thumbs per row, and no empty image at the end, if i'm able. i can deal w/ it if row one or the last row have to be different to fit into a function, as long the function itself is clean... i just don't want a broken image, or images floating outside of my divs (too many per row).
thanks!!