Heh, I'm not really sure, I basically copy and pasted the whole code. The function is used here:
natcasesort($images); // back to original directory:
I'm not sure if that sorts the array or not, because honestly this is my first time even creating a PHP file. I have done a bit of programming before, but nothing to serious.
Here is my page: http://www.squarewheelgames.com/comic.php
Ignore the comics, for now there just to test the page out and have a bit of content. If it helps, here is my full code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
<title>Images</title>
<!-- link rel='stylesheet' href='/include/style.css' type='text/css' -->
<style type="text/css">
<!--
#image
{
width: 800px;
margin: 1em auto;
padding: 10px;
border: outset 2px black;
background-color: silver;
color: black;
overflow: auto;
text-align: center;
}
-->
</style>
</head>
<body>
<div id="image">
<?php
error_reporting(E_ALL | E_STRICT);
$imageDir = '/images/comics'; // web path to image directory:
$thisDir = getcwd();
chdir($_SERVER['DOCUMENT_ROOT'] . $imageDir);
$images = glob('*.png'); // get all the png files into an array, then sort it:
natcasesort($images); // back to original directory:
chdir($thisDir); // back to original directory
// get requested image number, if any:
$imgNbr = (isset($_GET['img']) && array_key_exists($_GET['img'], $images)) ?
$_GET['img'] : 0 ; // default to first image in array
// ouput requested image
echo "<img src='$imageDir/{$images[$imgNbr]}' alt=''><br>\n";
echo "<p>";
// previous link:
if($imgNbr > 0)
{
$prev = $imgNbr - 1;
echo "<a href='{$_SERVER['PHP_SELF']}?img=$prev'><img src='images/carrots/Back Arrow.png' border=0></a>\n";
}
// next link:
if($imgNbr < (count($images) - 1))
{
$next = $imgNbr + 1;
echo "<a href='{$_SERVER['PHP_SELF']}?img=$next'><img src='images/carrots/Forward Arrow.png' border=0></a>\n";
}
?>
</div>
</body>
</html>
If you don't mind, I have a question on top of this. I've been wondering why the code that is commented out still styles the page?
<!--
#image
{
width: 800px;
margin: 1em auto;
padding: 10px;
border: outset 2px black;
background-color: silver;
color: black;
overflow: auto;
text-align: center;
}
-->
Thanks so much.