ARTLUNG LAB Share

Created April 14 2001

PHP AutoMagic Gallery Listing

Why?

This is a small project driven by my desire to have a simple page I could drop into a folder full of images and get a clean, simple listing of the images, plus links to the images in a way that was somewhat attractive.

See it in action at https://artlung.com/images/

Feel free to use it -- just copy and paste the source below. use a filename that's the default file format that processes php. Usually index.php or index.php3. The script doesn't care either way.

What do you think?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
                "https://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
   <title>a picture is worth a thousand words</title>
</head>
<body bgcolor="#ffffff">
<!-- I'm sorry, I include the height attribute in the table tag.       -->
<!-- it is the only thing which will prevent this page from validating -->
<!-- @ https://validator.w3.org/                                        -->
<table width="100%" height="94%" border="0" cellspacing="0" cellpadding="0">
   <tr>
      <td align="center">
<?php
if (!isset($i)) { // this first bit determines if the page got passed $i
   $directory = "./"; // this decides what directory we want to work on
   exec("ls -r $directory*.jpg", $contents); // list the jpegs (modify as appropriate)
   $i = 0;
   while (($contents[$i])) // this bit makes links for all the images
      {
       echo "<a href='./?i=$directory$contents[$i]'>$contents[$i]</a><br>\n";
       $i++;
      }
   $noback=1; // if we're listing images, we don't want to go back
} elseif (is_file($i)) { // is $i an image in the filesystem? this is important!
   $size = GetImageSize($i); // grabs the height and width tags, providing an html
                             // fragment we will use later. best web practice is to 
                             // include height and width tags in your images
                             // https://www.php.net/manual/en/function.getimagesize.php
?>
<?php // and we finally write the html for the image. First the src,
      // then the height and width, and a pretty border. Season to taste. ?>
<img src="<?php echo $i; ?>" <?php echo $size[3]; ?> alt="" border="5">
<?php // if $i is not a file, we may have url hacking, or a broken URL,
      // maybe from an emailed link? In any case, the [ main ] link
      // will take them the main directory listing where they
      // can get at your pictures. so maybe it's not as stupid
      // a program as it claims to be. ?>
<?php } else { ?>
         <p>
            there's something wrong here.<br>
            unfortunately i'm a stupid program<br>
            and i don't know what the problem is.<br>
            <br>
            sorry.
         </p>
<?php } ?>
      </td>
   </tr>
<?php if ($noback==0) { ?>
   <tr>
      <td valign="bottom" align="center">
         <small>
            <a href="./">[ main ]</a>
         </small>
      </td>
   </tr>
<?php }; ?>
</table>

<!-- this by Joe Crawford, April 2001 https://www.artlung.com/ -->
</body>
</html>