Mini Photo Gallery

By F*U*R*B*Y* on Aug 06, 2008

This is a miniture photo gallery....

Useage: show_image('./directory/goes/here/to/our/images/');

and it'll show all the jpg,png,gif and jpeg's :)

Example: http://www.xstaticcodes.com/gallery.php

<html>
<head>
<title>Web Admin</title>
<style type="text/css">
body { font: small sans-serif; size: 4px; text-align: center }
a, a:visited { text-decoration: none; color: navy }
hr { border-style: none; height: 1px; background-color: silver; color: silver }
#main { margin-top: 6pt; margin-left: auto; margin-right: auto; border-spacing: 1px }
#main th { background: #eee; padding: 3pt 3pt 0pt 3pt }
.listing th, .listing td { padding: 1px 3pt 0 3pt }
.listing th { border: 1px solid silver }
.listing .filename { text-align: left }
</style>
</head>
<body>
<table id="main">
<!-- <tr><td colspan="7" style="height: 1em"></td></tr> -->
<tr class="listing">
<?php

function list_files($d) {
    $i = 0;
    $contents =  scandir($d);
    $num = count($contents);
    $x = 0;
    while ($num > $x) {
        if ($contents[$x] != "."  &&  $contents[$x] != "..") {
            if(is_file($d."/".$contents[$x]) || is_file($contents[$x])) {
                $files[count($files)] = $contents[$x];
            }
            else {
                $dir[count($dir)] = $contents[$x];
            } 
        }
        $x++;
    }

    $a = 0;
    $num = count($dir);
    while ($a < $num) {
        if(is_dir($dir[$a])) {
            if($handle = opendir($dir[$a])) {
                while($file = readdir($handle)) {
                    if($file != "." && $file != "..") {
                        if ((strtolower(strrchr($file,".")))) {
                            if ((preg_match("/.jpg/is", $file)) || (preg_match("/.png/is", $file)) || (preg_match("/.gif/is", $file)) || (preg_match("/.jpeg/is", $file))) {
                                if ($i=="5") { echo '</tr><tr class="listing">'; $i = 0; }
                                echo '<th width="120" class="filename"><a href="'.$dir[$a].'/'.$file.'"><img src="'.$dir[$a].'/'.$file.'" alt="'.$dir[$a].'/'.$file.'" width="120" height="120" /></a></th>';
                                $i++;
                            }
                        }
                    }
                }
                closedir($handle);
            }
        }
        $a++;
    }

    $x = 0;
    $num=count($files);
    while ($x < $num ) {
        if($files[$x] != "." && $files[$x] != "..") {
            if ((strtolower(strrchr($files[$x],".")))) {
                if ((preg_match("/.jpg/is", $files[$x])) || (preg_match("/.png/is", $files[$x])) || (preg_match("/.gif/is", $files[$x])) || (preg_match("/.jpeg/is", $files[$x]))) {
                    if ($i=="5") { echo '</tr><tr class="listing">'; $i = 0; }
                    echo '<th width="120" class="filename"><a href="'.$files[$x].'"><img src="'.$files[$x].'" alt="'.$files[$x].'" width="120" height="120" /></a></th>';
                    $i++;
                }
            }
        }
        $x++;
    }
}
list_files('./');
?>

</tr>
</body>
</html>

Comments

Sign in to comment.
Hawkee   -  Aug 16, 2008

Not bad, but your HTML could be a bit cleaner. Also a good idea to put the number of columns into a variable so you don't need to change out all the 5's to add or remove them.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.