View Full Version : creating a txt gallery using includes

12-22-2003, 01:23 AM
I'm trying to create a gallery of txt files on my website. I've just recently learned about server side includes and how to use them to post the contents of files inside of webpages. What I'm wondering is if anybody knows how I could make a slide show of the files, operated by "back" and "next" links, without hardcoding the filenames to the webpage. I was thinking along the lines of having a numerically-ordered directory of txt files (001, 002, 003, etc). The "next" link would lead you to the next file in the directory . . . "back" would take you backward numerically. An example of what I'm looking for can be found on this page:


How is this kind of thing done?


12-22-2003, 04:36 PM
Should be possible by passing a numerical parameter in the URL, and using this to include the text file, then for the 'next' or 'previous' links, reading off this parameter and incrementing or decrementing it.

08-01-2005, 04:34 AM
Current URL /script.php?id=5


$max = 10; // The highest file number
$min = 0; // The lowest file number

if ($id == $min)
$prev = $max; // Sets $prev to $max since there's nothihng below $min
$prev = $id - 1; // makes $prev = 4

if ($id == $max)
$next = $min; // Sets $next to $min since there's nothing above $max
$next = $id + 1; // makes $next = 6

include ("$id.txt");


<a href="/script.php?id=$prev">Prev</a>|<a href="/script.php?id=$next">Next</a>