Jump to content

How sort my images on this php script


johngary

Recommended Posts

I'm bit new to php and I got this code on my site but however Id like this to change the images to show up in the right order of sequence. My images are number from 1.jpg, 2.jpg and so on but on my site it appears to be in random...

Anyone please can fixed this...

 

<?php

$p = $_GET['p'];

if ($handle = opendir("images/rootfolder/")) {

$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];

}

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.