Photo gallery with Mig


Mig is a neat, no thrill, PHP script to build a photo gallery. As of oct 2003, it doesn't support on-the-fly thumbnailing or through-the-web uploads, but it doesn't require MySQL or any extra components, and can be set up in a couple of minutes. It can also be added to portals such as PHPNuke, PostNuke, PHPWebSite, PHPWebThings, or Xoops.


  1. In the docs/ section of your web server, upload the following Mig files and directories:
    1. index.php
    2. config.php (renamed from config.php.default)
    3. images/
    4. templates/ (if you're not using any portal, you can remove the sub-directory portals/)
  2. Create a directory named albums/
  3. At this point, you should have the following tree:
    1. index.php
    2. config.php
    3. albums/
    4. templates/
    5. images/
  4. Cd to albums/, and upload pictures
  5. Use your favorite thumbnail application, and create thumbnails for the pictures you just uploaded. Each thumbnail must be named exactly after the picture it references (ie. no t_, tn, etc.)
  6. Inside albums/, create a sub-directory named thumbs/, and upload thumbnails therein
  7. Hit http://localhost: You should see a thumbnails gallery of the pictures you uploaded, each clickable to get the regular size picture it references



templates/style.css, folder.html, image.html

Each folder can have its own templates/ . See the FolderTemplate section of the mig_cf document for more information.


Tags available in any template:

Tags available in folder.html:

Tags available in image.html:

#include "filename";

Included files must be located in the templates directory. As of version 1.2.5 it is possible to include PHP files as well as other types of files.  The one difference is that for PHP files the filename must have an extension of either ".php" or ".php3".

If you are using PHP-Nuke, PostNuke or phpWebThings, these three files will not exist.  This is called "Nuke" mode.  In their place you'll find mig_folder.php and mig_image.php which are the same basically as folder.html and image.html respectively. In Nuke mode the CSS file is not used (Nuke systems have their own CSS already).



To display a text common to a gallery, use the Bulletin tag:

    We spent four days in Rome.  Even with four whole days to tour
    the area, we found we couldn't cover everything.  The Vatican
    alone took most of the second day, and we only saw half of it.


If you want a comment to be displayed either below the picture (when displayed in full size) or as the ALT or TITLE attribute (when shown as a thumbnail), add a file named, with the following format:

<Comment "pic1.jpg">
This is the comment/ALT stuff for this picture


(If you want to use shorter comments for thumbnail hover-overs and leave your longer comments only on the image page itself, see the mig_cf document and read about <Short> tags).

Certain HTML elements don't mix well with ALT and TITLE, and should be avoided, notably things like <A HREF>.  You can turn ALT/TITLE tags off if you wish, by setting $suppressAltTags to TRUE in config.php.

Sometimes you want a long comment on the image itself, but a shorter one used in the ALT and TITLE tags on the thumbnail page (for hovering over links).  You can use the <Short> tag in files for that. This element works just like <Comment> except that it is used only in the hover-over tags on thumbnail pages.

<Short "image_file">
[some text]

If there is a <Comment> block but no <Short> block for an image, the <Comment> block will be used for the hover-over.

Folder icon

FolderIcon folder_name icon_file.gif

If you are using $randomFolderThumbs, note that FolderIcon overrides that setting. If you want to use a specific thumbnail for a given directory as its folder icon, you instead want to look at the UseThumb directive.

Thumbail as folder icon

 UseThumb folder_name image_name

Per-folder template

FolderTemplate /path/to/file.tmpl
FolderTemplate file.tmpl

Per-folder page title

PageTitle This is my Page Title for this Folder

Per-folder maintainer address


Per-folder column settings

MaxFolderColumns 2
MaxThumbColumns 4

Hidding items

Useful to hide files or folders.


Sort order


EXIF infos

EXIF data generally contains information such as shutter speed, aperture, ISO rating, the original shooting date and time, and sometimes comments.

Mig can read some, but not all, of this data.  Future versions of Mig may understand more of the data than it currently does.

By default Mig only shows embedded comments.  To show more, adjust the format string $exifFormatString found in config.php.  There are examples in that file that explain how the formatting works.

Note that most graphic editors destroy EXIF blocks!  They don't know how to write them so when they save images, they are simply not written back into the file.

Short URLs


A.k.a. "jump tags". Add a line to config.php that adds to the jump map.

$jumpMap['house'] = 'currDir=./Our%20House/Before%20We%20Redecorated'; OR

This works with Apache web servers.  I don't know if it works with anything else.  If you're running something other than Apache, let me know how you fare with this feature.



Generate a hashed password:


        $pass = 'somepassword';

        $salt = 'Ai';

        print crypt($pass, $salt);


The salt is any two-character combination - it is used to seed the random generation process, so to speak.  Any two characters are good enough (but ":" (colon) can't be used in a salt string).

It's equally easy in Perl:     perl -e 'print crypt("password","xy"),"\n";'  Where password should be the password to encrypt, and xy is the two-character salt (any two characters beside a colon (":") will do).

Edit config.php

$protect['./Pictures_of_me']['joe'] = 'IBDXWbkBirMfU';

To protect the main folder (root), either use .htaccess, or use Mig's password scheme (less securely):

    $protect['.']['kate'] = 'BSkfNxImwPHeQ';


Sorting items

Items can be sorted in a custom order if desired (rather than relying on the default alphabetical order).  To do this define a <sort> block in  See the mig_cf document for details.

Using other languages

It's also possible to use multiple languages with Mig, although you must pick one to be the default language - that is the one you define in config.php in the $mig_language variable.  To change the language, simply add the parameter mig_dl=LANG to a URL as a parameter.  For example, take this URL:

Assuming the default is something else, you can tell Mig to display it in Spanish by doing this:

You can add links to your template files which switch languages on the fly using the template keyword newLang like this:

    <a href="%%newLang%%=es">Espanol</a>

    <a href="%%newLang%%=it">Italiano</a>

Showing pictures in pop-up windows

Pop-up windows can be used (see the $imagePopup option in config.php).

Handling large galleries

Sometimes a gallery gets so large, fitting all the thumbnails on one page becomes a problem (think of a gallery with 500 images).  To resolve this, Mig paginates large galleries.  By default, any gallery with more than 20 images will go into a paged mode (4 images across, in 5 rows).

This can be controlled using two options in config.php: $maxThumbColumns and $maxThumbRows.  Their names are self-explanatory.  Set $maxThumbColumns to the maximum number of columns desired (how many thumbnails across from left to right in one row).  Set $maxThumbRows to the maximum number of rows per page/screen.  The defaults are 4 columns and 5 rows (for 20 images per page).

Custom icon for the folder icon

Instead of using the generic folder icon for folder views, Mig can use a randomly selected thumbnail from the folder as the icon.  To turn this behavior on, set $randomFolderThumbs to TRUE in config.php. (See also $folderNameLength and $useRealRandThumbs.)

To use a specific icon as the folder icon, check out the UseThumb option in files.  See the mig_cf document for more information.

Tip & Tricks

This is a Perl utility provided by Mig to build thumbnails. It requires ImageMagick to run.

my $globalConfig = $mydir . '/../config.php';       # Global config file

            $cmd = "convert -geometry $SIZE -quality $quality";

d:\temp\stuff> -a -t ERROR: marker type "" is invalid. Only "prefix" and "suffix" are valid.  This could be specified as an argument for -M, or can be specifed in your config.php file (see $markerType)

Batch file

If you'd rather use a DOS batch file instead of

IF NOT EXIST \thumbs mkdir thumbs
for %%f in (*.jpg *.gif) do c:\imagem\imconvert -size 120x120 %%f -resize 120x120 +profile "*" thumbs\%%f

Displaying folder names with spaces

To make things more visually appealing, if a folder name contains underscores, eg. my_folder/, Mig will display it with spaces, ie. "my folder".