Here is how I have done it in two different ways:
In both cases I have the pictures on the server in two versions. One is the full size picture - like seal.jpg - and one is a thumbprint - smallseal.jpg.
1)
I scan the directory for all files called small*.jpg and get the names of the thumbs to show. Then I trip the 'small' from the name and hence get the name for the big picture. This name I use as a parameter for the PHP file, which shows the big picture like big.php?show=seal.jpg. In this file I look for the big picture, get its size data with image_size() and display it.
I have also made an incarnation of this function that looks for a small txt file, which contains the caption. This file is called seal.jpg.txt in the abovce example. If it exists, the content is read and displayed as a caption. If not, there's no caption.
2)
I have all picture data in a database. It contains a lot of information about each picture including the base name for the picture - seal in the above example. I then generate the filenames from this name by adding .jpg and small for the thumbprint. I can then make the thumbprint page by traversing the database and showing all thumbprints.
In this version I just refer to the picture by a database id number. The big.php file will then be called with one argument like in big.php?id=123. This script will then get info on picture number 123 from the database, generate the file name, get description, caption and other stuff from the database and display the picture.
Hope this is clear and can help you.
Martin