johngary Posted August 12, 2009 Share Posted August 12, 2009 I have place a php file for image viewer and everything works fine. But my problem here is that when I open it the pictures were showing in random order not in proper sequence of number. Can anyone help me with this php file to make the pictures shows up in the right sequence of number. like 1.jpg-2.jpg....... Thank you very much and your help will be much appreciated. The pictures on my server arrange like this: 1.jpg 11.jpg 12.jpg 2.jpg 22.jpg 4.jpg and so on.... All the photos are numbered also in order. When I open the page it shows the name of the page not the number of the image it looks like this: www.mysite.com/file.php (with a picture) then when I click the next button that shows up like: www.mysite.com/file.php?p=18.jpg then next image shows like: www.mysite.com/file.php?p=6.jpg and so on like in random order. Can you correct it to make it in right order like: p=1, p=2, p=3 and so on... This is the code I placed. $p = $_GET['p']; if ($handle = opendir("images/myfolder/")) { $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/170001-can-anyone-help-me-to-edit-this-php-image-viewer/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.