My name is John from Edmonton, Alberta.
Im new to php right now and I'm getting interested on knowing this script.
I just made a personal photo album site and used this php code which
I've got from the net and it is working fine. But my problem here is that
the pictures were showing up in random order surprisingly. I numbered my
images like 01.jpg and so on. When I open the page it start showing the
first picture like: "http://www.mysite.com/file.php (and a picture) then going through
the rest the pictures were showing up like: "http://www.mysite.com/file.php?p=48.jpg, 39.jpg, 57.jpg randomly.
I was so desperate for someone who can help me this and I humbly ask any help
if it is ok from you. Thank you so much and your help will be much appreciated.
This is the code:
<?php
/*
* Installation:
* 1.) Place your photos into the images directory.
* - Photos will be displayed in alphabetical order.
* 2.) Rename the "images/mypictures/" folder to anything you wish.
* - Example: paris-photo-album
* 3.) Upload the renamed folder and all of its contents to your server.
* - If your domain is www.mysite.com, your album can be viewed at
* http://www.mysite.com/images/mypictures/
* That's it! Make multiple albums by repeating the above 3 steps.
*/
/*
* You shouldn't need to change anything beyond this.
*
*/
$p = $_GET['p'];
if ($handle = opendir("images/mypictures/")) {
$i = 1;
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$img[$i] = $file;
if ($p == $img[$i]) {
$ci = $i;
}
$i++;
}
}
closedir($handle);
$ti = $i - 1;
$pi = $ci - 1;
if ($p == "") {
$ni = $ci + 2;
} else {
$ni = $ci + 1;
}
$prevNext = "";
if ($pi > 0) {
$piFile = $img[$pi];
$prevNext .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $piFile . "\" title=\"show previous image\">Previous</a>";
} else {
$prevNext .= "Previous";
}
$prevNext .= " | ";
if ($ni <= $ti) {
$niFile = $img[$ni];
$prevNext .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $niFile . "\" title=\"show next image\">Next</a>";
} else {
$prevNext .= "Next";
}
if ($p == "") {
$p = $img[1];
}
}
?>
<title><?php echo $albumName; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="imagetoolbar" content="no">
<style type="text/css">
body {
font-family: arial, helvetica, sans-serif;
font-size: 12px;
background-color: #ffffff;
color: #333333;
}
td, select, input {
font-family: arial, helvetica, sans-serif;
font-size: 11px;
}
p {
font-family: arial, helvetica, sans-serif;
font-size: 11px;
line-height: 16px;
}
h1 {
font-family: georgia, times, times new roman, serif;
font-size: 18px;
font-weight: bold;
margin: 0px 0px 10px 0px;
}
.hRule {
border-top: 1px solid #cdcdcd;
margin: 0px 0px 10px 0px;
}
.nextPrevious {
font-size: 12px;
color: #ff9900;
padding-bottom: 15px;
}
a, a:visited {
font-size: 12px;
color: #ffffff;
text-decoration: none;
}
a:active, a:hover {
font-size: 12px;
color: #ff9900;
text-decoration: underline;
}
</style>
</head>
<body>
<h1><?php echo $albumName; ?></h1> <table border="0" cellpadding="0" cellspacing="0" align="center">
<tr align="right">
<td class="nextPrevious"><?php echo $prevNext; ?></td>
</tr>
<tr align="center">
<td><img src="images/mypictures/<?php echo $p; ?>" alt="<?php echo $$albumName; ?>" border="0">
</td>
</tr>
</table>
</body>
</html>