ID:183299
 
A friend recently sent me a very long code. Basically, it makes a page with an image, with the standard comic controls (first, back, next, latest - this is when you're in the middle, anyway, when you're on the first, it takes away first and back, and when you're on the latest it takes away next and latest)

However, I want to add comments to these pictures, along the bottom. I tried an experiment to see if I could change one part where it told the page what file types to look for (png, jpeg and...bmp *cringe*) to include .htm, to see if that would work, then created a file of each type with the same name as the images, so we had 001.png and 001.htm, but it came up with errors.

I'll be able to post a sample page of this later, as I haven't got access to it at the moment (at work ^^;) but does anyone know of a method I could look into to do this?

Any and all help appreciated :D
If you're interested in digging around a little http://www.codewalkers.com is pretty good. Their forum may be better suited to your questions.

Adding captions shouldn't be too hard, but I can't really help you much without some more info on how the current system works.

Also, what program are you using to read the code? Notepad does the job, and a lot of people like to boast that it's all they need, but a good text editor will do wonders. With the proper editor it's a lot easier to read and follow the flow of a program.
In response to DarkView
This bit's a bit long. I made up a quick test page, I'll stick some demo pics in there when I get home (with Freehostia, you can't upload from an external source, only from your pc...which is mean!)
http://tangents.freehostia.com/test/test.php

<?php
$listdir = "test"; // Customizeable
$listid = $_GET['id']; // Leave this alone

/* This function is the one I've been using forever. It just goes and grabs
an alphabetical array of files in the specified directory. */


function getlist_alpha(&$afiles, $listdir) {
if (is_dir($listdir)) {
if ($thisdir = opendir($listdir)) {
while (($afile = readdir($thisdir)) !== false) {
if (!is_dir($afile) && preg_match("/.*\.(gif|jp(e)?g|png)/i", $afile)) {
$afiles[] = $afile;
}
}
closedir($thisdir);
return $afiles;
}
}
}

/* This function actually creates the strings to be put in the selection list. */

function printoptions($item1, $key, $listdir) {
if (strpos($item1, ".")) { $item1 = explode(".", $item1);
$item1 = $item1[0]; }
$ffile = "$listdir/$item1";
if ($item1 == $_GET['id']) echo "\n<option selected>"; else echo "\n<option>"; echo "$item1</option>";
}

/* This function sorts a collected array and then uses printoptions to make the list. */

function comiclist($listdir, $listid) {
echo "<center><form name=\"comiclist\">\n<select name=\"id\" id=\"id\">";
$alisting = getlist_alpha($listart, $listdir);
rsort($alisting);
array_walk($alisting, 'printoptions', $listdir);
echo "</select>\n<input type=\"submit\" value=\"Go\" action=\"selection.php\" method=\"get\">\n</form></center>";
}

comiclist($listdir, $listid);


?></p>
<div align="center">
<p><?php
$cdir = 'test';
$getc = $_GET['id'];
$phpfile = $_SERVER['PHP_SELF'];

function check_zeros($num) {
$digits = 3;
$pad = strval(0);
$num = strval($num);

if (strlen($num) != $digits) {
$num = str_pad($num, $digits, $pad, STR_PAD_LEFT);
}
return $num;
}


function find_comic($idnum, $dir) {
if (is_dir($dir)) {
if ($cdir = opendir($dir)) {
if ($idnum != 'all') $idnum = check_zeros($idnum);
if ($idnum == 'all') $num = 0;
while (($file = readdir($cdir)) !== false) {
if ($file != '.' && $file != '..') {
if ($idnum != 'all') {
if (preg_match("/$idnum\.(gif|jp(e?)g|png)/i", $file)) {
$idnum = $file;
}
}
else if (preg_match("/.*\.(gif|jp(e?)g|png)/i", $file)) {
$num++;
}
}
}
}
closedir($cdir);
}
if ($idnum == 'all') return $num;
else return $idnum;
}



$max_comics = find_comic("all", $cdir);

if ($getc < 1 || $getc == NULL || $getc > $max_comics)
$getc = $max_comics;

if ($getc > 1)
$getp = $getc - 1;
else
$getp = NULL;

$getn = $getc + 1;
$cshow = find_comic($getc, $cdir);

echo "<img src=\"$cdir/$cshow\" border=\"0\" /><br>";

echo "<br><br>";

if ($getc > 2)
echo "<a href=\"$phpfile?id=1\"><img src=\"first.gif\" border=\"0\"></a>";

if ($getc > 1)
echo "<a href=\"$phpfile?id=$getp\"><img src=\"back.gif\" border=\"0\"></a>";

echo "<a href=\"http://tangents.freehostia.com\"><img src=\"home.gif\" border=\"0\"></a>";

if ($getc < $max_comics)
echo "<a href=\"$phpfile?id=$getn\"><img src=\"next.gif\" border=\"0\"></a>";

if ($getc != $max_comics && $getc < $max_comics - 1)
echo "<a href=\"$phpfile?id=$max_comics\"><img src=\"newest.gif\" border=\"0\"></a>";
?>


Will that be of assistance? I would've posted it on the page, but I couldn't remember the tag for showing code ^_^;