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
https://forums.phpfreaks.com/topic/170119-how-sort-my-images-on-this-php-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.