PHP Gallery not correctly displaying first two images in gallery












0















For whatever reason, the first two images in every gallery that I have on my site are not being correctly displayed. I have looked in the page source and found this:



<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=1');"><img src="/galleries/053/thumbs/." class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=2');"><img src="/galleries/053/thumbs/.." class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=3');"><img src="/galleries/053/thumbs/053img009.jpg" class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=4');"><img src="/galleries/053/thumbs/053img008.jpg" class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=5');"><img src="/galleries/053/thumbs/053img011.jpg" class="thumb_img" border="0" /></a></td>


I'm guessing its something in the initialisation of the FOR loop but I am not seeing here, but its clearly wrong for the first two images. Here is the relevant code in the script.



<?php

error_reporting(E_ALL);

require("config.php");
require("common.php");

$gallery = $_GET['page'];
$gallerydir = DOC_ROOT . GALLERY_ROOT . '/' . $gallery;
$imglist = getImageList($gallerydir);
$imgcnt = count($imglist);

$currpage = (isset($_GET['currpage']))
? (int) $_GET['currpage']
: 1;

// get page elements
$js = getJavaScript($imglist);
$thumb_table = getThumbTableHTML($gallery, $imglist, $imgcnt, $currpage);
$image_cnt = getImageRangeHTML($imgcnt, $currpage);
$page_nav = getPageNavHTML($imgcnt, $currpage, $gallery);

// load template header and body
$head = file_get_contents("./template/header.html");
$body = file_get_contents("./template/thumb_page.html");

// insert page elements
$head = str_replace('<-- JAVASCRIPT -->', $js, $head);
$body = str_replace('<-- THUMBNAIL_TABLE -->', $thumb_table, $body);
$body = str_replace('<-- IMAGE_COUNT -->', $image_cnt, $body);
$body = str_replace('<-- PAGE_NAVIGATION -->', $page_nav, $body);

// output
echo $head;
echo $body;
//*********************************************************************
// Begin thumbnail page related functions
//*********************************************************************

function getImageRangeHTML($imgcnt, $currpage) {

$max_per_page = TABLE_COLS * TABLE_ROWS;
$pagecnt = getThumbPageCount($imgcnt);
$first_image = ($currpage - 1) * $max_per_page + 1;
$last_image = ($currpage == $pagecnt)
? $imgcnt
: $currpage * $max_per_page;

$str = "
<font size="2" face="Verdana, Geneva, sans-serif"><i>
$imgcnt images
</i></font>
";

return $str;
}
//*********************************************************************

function getPageNavHTML($imgcnt, $currpage, $gallery) {

$pagecnt = getThumbPageCount($imgcnt);
$self = $_SERVER['PHP_SELF'];

// only proceed if there is more than 1 page of thumbs
if ($pagecnt == 1) { return; }

$str = "<ul>n";

for ($i = 1; $i <= $pagecnt; $i++) {

if ($i == $currpage) {
$str .= "<li class="active">$i</li>";
} else {
$str .= "<li><a href="javascript:imgSubmit('$self?";
$str .= "gallery=$gallery&currpage=$i');">$i</a></li>";
}
}

$str .= "</ul>n";
return $str;
}

//********************************************************************

function getThumbTableHTML($gallery, $imglist, $imgcnt, $currpage) {
$max_per_page = TABLE_COLS * TABLE_ROWS;

// set index of page's first image in image list array
$first_image_index = ($currpage - 1) * $max_per_page;

// set index of page's last image in image list array
$last_image_index = ($imgcnt < $currpage * $max_per_page)
? $last_image_index = $imgcnt
: $currpage * $max_per_page;

$str = '<table border="0" id="thumb_table">' . "n";

// loop control var
$column_cnt = 1;

// loop through current page images
for ($i = $first_image_index; $i < $last_image_index; $i++) {
# build path to thumb
$thumburl = GALLERY_ROOT . "/$gallery/thumbs/" . $imglist[$i];

// insert row tag if this is the first column
if ($column_cnt == 1) { $str .= "<tr>n"; }

// insert thumbnail, and surrounding html
$str .= "<td>";
$str .= "<a href="javascript:imgSubmit('image.php?gallery=$gallery";
$str .= "&imgnum=" . ($i + 1) . "');">";
$str .= "<img src="$thumburl" class="thumb_img" ";
$str .= "border="0" /></a>";
$str .= "</td>n";

if ($column_cnt == TABLE_COLS) {
$str .= "</tr>nn";
$column_cnt = 1;
} else {
$column_cnt++;
}
}

$str .= "</table>n";
return $str;
}

// *********************************************************************

function getThumbPageCount($imgcnt) {

$page_cnt = (int) (($imgcnt - 1) / (TABLE_COLS * TABLE_ROWS)) + 1;
return $page_cnt;
}

// *********************************************************************
?>


Here is the relevant code for the GetImageList() function



    function getImageList($gallerydir) {
if (isset($_POST['imglist'])) {
$imglist = $_POST['imglist'];
} else {
$fh = opendir("$gallerydir/thumbs");

// read directory, and loop through retreived filenames
while ($file = readdir($fh)) {
// if image, add filename to image list
if (!preg_match(".(jpg|gif|png|jpeg|jpe)$", $file)) {
$imglist = $file;
}
}
closedir($fh);
}

if (is_array($imglist)) {
ksort($imglist);
} else {
$imglist = false;
}
return $imglist;
}

//*********************************************************************
// Javascript writes image list as http posted array

function getJavaScript($imglist) {
$str = '
<script language="JavaScript">
function imgSubmit(s) {
document.img.method = "post";
document.img.action = s;
document.img.submit();
}

function imgList() {
';
$str .= "tvar imglist = new Array('" . implode("', '", $imglist) . "');n";
$str .= '
for (var i=0; i < imglist.length; i++) {
document.write ("<input type="hidden" name="imglist" ");
document.write ("value="" + imglist[i] + "" />");
}
}
</script>
';
return $str;
}

//*********************************************************************

?>









share|improve this question




















  • 2





    You’re listing the contents of a directory somewhere and that contains also entries . and .. so you’ll have to filter those out

    – Sami Kuhmonen
    Jan 2 at 8:00











  • It's probably your getImageList() method that doesn't filter out the current (.) and parent (..) directory

    – kerbholz
    Jan 2 at 8:05











  • I've added the getImageList() function code to my question.

    – Mark J
    Jan 2 at 8:14











  • Thank you for the edits. I really appreciate it. Unfortunately it has yet to solve the problem. One thing I discovered was that all of the images available to the gallery are still being posted, the two pictures that don't work do not even exist and are addons to the total amount of images. Is it something in the for loop maybe?

    – Mark J
    Jan 3 at 1:15
















0















For whatever reason, the first two images in every gallery that I have on my site are not being correctly displayed. I have looked in the page source and found this:



<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=1');"><img src="/galleries/053/thumbs/." class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=2');"><img src="/galleries/053/thumbs/.." class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=3');"><img src="/galleries/053/thumbs/053img009.jpg" class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=4');"><img src="/galleries/053/thumbs/053img008.jpg" class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=5');"><img src="/galleries/053/thumbs/053img011.jpg" class="thumb_img" border="0" /></a></td>


I'm guessing its something in the initialisation of the FOR loop but I am not seeing here, but its clearly wrong for the first two images. Here is the relevant code in the script.



<?php

error_reporting(E_ALL);

require("config.php");
require("common.php");

$gallery = $_GET['page'];
$gallerydir = DOC_ROOT . GALLERY_ROOT . '/' . $gallery;
$imglist = getImageList($gallerydir);
$imgcnt = count($imglist);

$currpage = (isset($_GET['currpage']))
? (int) $_GET['currpage']
: 1;

// get page elements
$js = getJavaScript($imglist);
$thumb_table = getThumbTableHTML($gallery, $imglist, $imgcnt, $currpage);
$image_cnt = getImageRangeHTML($imgcnt, $currpage);
$page_nav = getPageNavHTML($imgcnt, $currpage, $gallery);

// load template header and body
$head = file_get_contents("./template/header.html");
$body = file_get_contents("./template/thumb_page.html");

// insert page elements
$head = str_replace('<-- JAVASCRIPT -->', $js, $head);
$body = str_replace('<-- THUMBNAIL_TABLE -->', $thumb_table, $body);
$body = str_replace('<-- IMAGE_COUNT -->', $image_cnt, $body);
$body = str_replace('<-- PAGE_NAVIGATION -->', $page_nav, $body);

// output
echo $head;
echo $body;
//*********************************************************************
// Begin thumbnail page related functions
//*********************************************************************

function getImageRangeHTML($imgcnt, $currpage) {

$max_per_page = TABLE_COLS * TABLE_ROWS;
$pagecnt = getThumbPageCount($imgcnt);
$first_image = ($currpage - 1) * $max_per_page + 1;
$last_image = ($currpage == $pagecnt)
? $imgcnt
: $currpage * $max_per_page;

$str = "
<font size="2" face="Verdana, Geneva, sans-serif"><i>
$imgcnt images
</i></font>
";

return $str;
}
//*********************************************************************

function getPageNavHTML($imgcnt, $currpage, $gallery) {

$pagecnt = getThumbPageCount($imgcnt);
$self = $_SERVER['PHP_SELF'];

// only proceed if there is more than 1 page of thumbs
if ($pagecnt == 1) { return; }

$str = "<ul>n";

for ($i = 1; $i <= $pagecnt; $i++) {

if ($i == $currpage) {
$str .= "<li class="active">$i</li>";
} else {
$str .= "<li><a href="javascript:imgSubmit('$self?";
$str .= "gallery=$gallery&currpage=$i');">$i</a></li>";
}
}

$str .= "</ul>n";
return $str;
}

//********************************************************************

function getThumbTableHTML($gallery, $imglist, $imgcnt, $currpage) {
$max_per_page = TABLE_COLS * TABLE_ROWS;

// set index of page's first image in image list array
$first_image_index = ($currpage - 1) * $max_per_page;

// set index of page's last image in image list array
$last_image_index = ($imgcnt < $currpage * $max_per_page)
? $last_image_index = $imgcnt
: $currpage * $max_per_page;

$str = '<table border="0" id="thumb_table">' . "n";

// loop control var
$column_cnt = 1;

// loop through current page images
for ($i = $first_image_index; $i < $last_image_index; $i++) {
# build path to thumb
$thumburl = GALLERY_ROOT . "/$gallery/thumbs/" . $imglist[$i];

// insert row tag if this is the first column
if ($column_cnt == 1) { $str .= "<tr>n"; }

// insert thumbnail, and surrounding html
$str .= "<td>";
$str .= "<a href="javascript:imgSubmit('image.php?gallery=$gallery";
$str .= "&imgnum=" . ($i + 1) . "');">";
$str .= "<img src="$thumburl" class="thumb_img" ";
$str .= "border="0" /></a>";
$str .= "</td>n";

if ($column_cnt == TABLE_COLS) {
$str .= "</tr>nn";
$column_cnt = 1;
} else {
$column_cnt++;
}
}

$str .= "</table>n";
return $str;
}

// *********************************************************************

function getThumbPageCount($imgcnt) {

$page_cnt = (int) (($imgcnt - 1) / (TABLE_COLS * TABLE_ROWS)) + 1;
return $page_cnt;
}

// *********************************************************************
?>


Here is the relevant code for the GetImageList() function



    function getImageList($gallerydir) {
if (isset($_POST['imglist'])) {
$imglist = $_POST['imglist'];
} else {
$fh = opendir("$gallerydir/thumbs");

// read directory, and loop through retreived filenames
while ($file = readdir($fh)) {
// if image, add filename to image list
if (!preg_match(".(jpg|gif|png|jpeg|jpe)$", $file)) {
$imglist = $file;
}
}
closedir($fh);
}

if (is_array($imglist)) {
ksort($imglist);
} else {
$imglist = false;
}
return $imglist;
}

//*********************************************************************
// Javascript writes image list as http posted array

function getJavaScript($imglist) {
$str = '
<script language="JavaScript">
function imgSubmit(s) {
document.img.method = "post";
document.img.action = s;
document.img.submit();
}

function imgList() {
';
$str .= "tvar imglist = new Array('" . implode("', '", $imglist) . "');n";
$str .= '
for (var i=0; i < imglist.length; i++) {
document.write ("<input type="hidden" name="imglist" ");
document.write ("value="" + imglist[i] + "" />");
}
}
</script>
';
return $str;
}

//*********************************************************************

?>









share|improve this question




















  • 2





    You’re listing the contents of a directory somewhere and that contains also entries . and .. so you’ll have to filter those out

    – Sami Kuhmonen
    Jan 2 at 8:00











  • It's probably your getImageList() method that doesn't filter out the current (.) and parent (..) directory

    – kerbholz
    Jan 2 at 8:05











  • I've added the getImageList() function code to my question.

    – Mark J
    Jan 2 at 8:14











  • Thank you for the edits. I really appreciate it. Unfortunately it has yet to solve the problem. One thing I discovered was that all of the images available to the gallery are still being posted, the two pictures that don't work do not even exist and are addons to the total amount of images. Is it something in the for loop maybe?

    – Mark J
    Jan 3 at 1:15














0












0








0








For whatever reason, the first two images in every gallery that I have on my site are not being correctly displayed. I have looked in the page source and found this:



<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=1');"><img src="/galleries/053/thumbs/." class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=2');"><img src="/galleries/053/thumbs/.." class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=3');"><img src="/galleries/053/thumbs/053img009.jpg" class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=4');"><img src="/galleries/053/thumbs/053img008.jpg" class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=5');"><img src="/galleries/053/thumbs/053img011.jpg" class="thumb_img" border="0" /></a></td>


I'm guessing its something in the initialisation of the FOR loop but I am not seeing here, but its clearly wrong for the first two images. Here is the relevant code in the script.



<?php

error_reporting(E_ALL);

require("config.php");
require("common.php");

$gallery = $_GET['page'];
$gallerydir = DOC_ROOT . GALLERY_ROOT . '/' . $gallery;
$imglist = getImageList($gallerydir);
$imgcnt = count($imglist);

$currpage = (isset($_GET['currpage']))
? (int) $_GET['currpage']
: 1;

// get page elements
$js = getJavaScript($imglist);
$thumb_table = getThumbTableHTML($gallery, $imglist, $imgcnt, $currpage);
$image_cnt = getImageRangeHTML($imgcnt, $currpage);
$page_nav = getPageNavHTML($imgcnt, $currpage, $gallery);

// load template header and body
$head = file_get_contents("./template/header.html");
$body = file_get_contents("./template/thumb_page.html");

// insert page elements
$head = str_replace('<-- JAVASCRIPT -->', $js, $head);
$body = str_replace('<-- THUMBNAIL_TABLE -->', $thumb_table, $body);
$body = str_replace('<-- IMAGE_COUNT -->', $image_cnt, $body);
$body = str_replace('<-- PAGE_NAVIGATION -->', $page_nav, $body);

// output
echo $head;
echo $body;
//*********************************************************************
// Begin thumbnail page related functions
//*********************************************************************

function getImageRangeHTML($imgcnt, $currpage) {

$max_per_page = TABLE_COLS * TABLE_ROWS;
$pagecnt = getThumbPageCount($imgcnt);
$first_image = ($currpage - 1) * $max_per_page + 1;
$last_image = ($currpage == $pagecnt)
? $imgcnt
: $currpage * $max_per_page;

$str = "
<font size="2" face="Verdana, Geneva, sans-serif"><i>
$imgcnt images
</i></font>
";

return $str;
}
//*********************************************************************

function getPageNavHTML($imgcnt, $currpage, $gallery) {

$pagecnt = getThumbPageCount($imgcnt);
$self = $_SERVER['PHP_SELF'];

// only proceed if there is more than 1 page of thumbs
if ($pagecnt == 1) { return; }

$str = "<ul>n";

for ($i = 1; $i <= $pagecnt; $i++) {

if ($i == $currpage) {
$str .= "<li class="active">$i</li>";
} else {
$str .= "<li><a href="javascript:imgSubmit('$self?";
$str .= "gallery=$gallery&currpage=$i');">$i</a></li>";
}
}

$str .= "</ul>n";
return $str;
}

//********************************************************************

function getThumbTableHTML($gallery, $imglist, $imgcnt, $currpage) {
$max_per_page = TABLE_COLS * TABLE_ROWS;

// set index of page's first image in image list array
$first_image_index = ($currpage - 1) * $max_per_page;

// set index of page's last image in image list array
$last_image_index = ($imgcnt < $currpage * $max_per_page)
? $last_image_index = $imgcnt
: $currpage * $max_per_page;

$str = '<table border="0" id="thumb_table">' . "n";

// loop control var
$column_cnt = 1;

// loop through current page images
for ($i = $first_image_index; $i < $last_image_index; $i++) {
# build path to thumb
$thumburl = GALLERY_ROOT . "/$gallery/thumbs/" . $imglist[$i];

// insert row tag if this is the first column
if ($column_cnt == 1) { $str .= "<tr>n"; }

// insert thumbnail, and surrounding html
$str .= "<td>";
$str .= "<a href="javascript:imgSubmit('image.php?gallery=$gallery";
$str .= "&imgnum=" . ($i + 1) . "');">";
$str .= "<img src="$thumburl" class="thumb_img" ";
$str .= "border="0" /></a>";
$str .= "</td>n";

if ($column_cnt == TABLE_COLS) {
$str .= "</tr>nn";
$column_cnt = 1;
} else {
$column_cnt++;
}
}

$str .= "</table>n";
return $str;
}

// *********************************************************************

function getThumbPageCount($imgcnt) {

$page_cnt = (int) (($imgcnt - 1) / (TABLE_COLS * TABLE_ROWS)) + 1;
return $page_cnt;
}

// *********************************************************************
?>


Here is the relevant code for the GetImageList() function



    function getImageList($gallerydir) {
if (isset($_POST['imglist'])) {
$imglist = $_POST['imglist'];
} else {
$fh = opendir("$gallerydir/thumbs");

// read directory, and loop through retreived filenames
while ($file = readdir($fh)) {
// if image, add filename to image list
if (!preg_match(".(jpg|gif|png|jpeg|jpe)$", $file)) {
$imglist = $file;
}
}
closedir($fh);
}

if (is_array($imglist)) {
ksort($imglist);
} else {
$imglist = false;
}
return $imglist;
}

//*********************************************************************
// Javascript writes image list as http posted array

function getJavaScript($imglist) {
$str = '
<script language="JavaScript">
function imgSubmit(s) {
document.img.method = "post";
document.img.action = s;
document.img.submit();
}

function imgList() {
';
$str .= "tvar imglist = new Array('" . implode("', '", $imglist) . "');n";
$str .= '
for (var i=0; i < imglist.length; i++) {
document.write ("<input type="hidden" name="imglist" ");
document.write ("value="" + imglist[i] + "" />");
}
}
</script>
';
return $str;
}

//*********************************************************************

?>









share|improve this question
















For whatever reason, the first two images in every gallery that I have on my site are not being correctly displayed. I have looked in the page source and found this:



<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=1');"><img src="/galleries/053/thumbs/." class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=2');"><img src="/galleries/053/thumbs/.." class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=3');"><img src="/galleries/053/thumbs/053img009.jpg" class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=4');"><img src="/galleries/053/thumbs/053img008.jpg" class="thumb_img" border="0" /></a></td>
<td><a href="javascript:imgSubmit('image.php?gallery=053&imgnum=5');"><img src="/galleries/053/thumbs/053img011.jpg" class="thumb_img" border="0" /></a></td>


I'm guessing its something in the initialisation of the FOR loop but I am not seeing here, but its clearly wrong for the first two images. Here is the relevant code in the script.



<?php

error_reporting(E_ALL);

require("config.php");
require("common.php");

$gallery = $_GET['page'];
$gallerydir = DOC_ROOT . GALLERY_ROOT . '/' . $gallery;
$imglist = getImageList($gallerydir);
$imgcnt = count($imglist);

$currpage = (isset($_GET['currpage']))
? (int) $_GET['currpage']
: 1;

// get page elements
$js = getJavaScript($imglist);
$thumb_table = getThumbTableHTML($gallery, $imglist, $imgcnt, $currpage);
$image_cnt = getImageRangeHTML($imgcnt, $currpage);
$page_nav = getPageNavHTML($imgcnt, $currpage, $gallery);

// load template header and body
$head = file_get_contents("./template/header.html");
$body = file_get_contents("./template/thumb_page.html");

// insert page elements
$head = str_replace('<-- JAVASCRIPT -->', $js, $head);
$body = str_replace('<-- THUMBNAIL_TABLE -->', $thumb_table, $body);
$body = str_replace('<-- IMAGE_COUNT -->', $image_cnt, $body);
$body = str_replace('<-- PAGE_NAVIGATION -->', $page_nav, $body);

// output
echo $head;
echo $body;
//*********************************************************************
// Begin thumbnail page related functions
//*********************************************************************

function getImageRangeHTML($imgcnt, $currpage) {

$max_per_page = TABLE_COLS * TABLE_ROWS;
$pagecnt = getThumbPageCount($imgcnt);
$first_image = ($currpage - 1) * $max_per_page + 1;
$last_image = ($currpage == $pagecnt)
? $imgcnt
: $currpage * $max_per_page;

$str = "
<font size="2" face="Verdana, Geneva, sans-serif"><i>
$imgcnt images
</i></font>
";

return $str;
}
//*********************************************************************

function getPageNavHTML($imgcnt, $currpage, $gallery) {

$pagecnt = getThumbPageCount($imgcnt);
$self = $_SERVER['PHP_SELF'];

// only proceed if there is more than 1 page of thumbs
if ($pagecnt == 1) { return; }

$str = "<ul>n";

for ($i = 1; $i <= $pagecnt; $i++) {

if ($i == $currpage) {
$str .= "<li class="active">$i</li>";
} else {
$str .= "<li><a href="javascript:imgSubmit('$self?";
$str .= "gallery=$gallery&currpage=$i');">$i</a></li>";
}
}

$str .= "</ul>n";
return $str;
}

//********************************************************************

function getThumbTableHTML($gallery, $imglist, $imgcnt, $currpage) {
$max_per_page = TABLE_COLS * TABLE_ROWS;

// set index of page's first image in image list array
$first_image_index = ($currpage - 1) * $max_per_page;

// set index of page's last image in image list array
$last_image_index = ($imgcnt < $currpage * $max_per_page)
? $last_image_index = $imgcnt
: $currpage * $max_per_page;

$str = '<table border="0" id="thumb_table">' . "n";

// loop control var
$column_cnt = 1;

// loop through current page images
for ($i = $first_image_index; $i < $last_image_index; $i++) {
# build path to thumb
$thumburl = GALLERY_ROOT . "/$gallery/thumbs/" . $imglist[$i];

// insert row tag if this is the first column
if ($column_cnt == 1) { $str .= "<tr>n"; }

// insert thumbnail, and surrounding html
$str .= "<td>";
$str .= "<a href="javascript:imgSubmit('image.php?gallery=$gallery";
$str .= "&imgnum=" . ($i + 1) . "');">";
$str .= "<img src="$thumburl" class="thumb_img" ";
$str .= "border="0" /></a>";
$str .= "</td>n";

if ($column_cnt == TABLE_COLS) {
$str .= "</tr>nn";
$column_cnt = 1;
} else {
$column_cnt++;
}
}

$str .= "</table>n";
return $str;
}

// *********************************************************************

function getThumbPageCount($imgcnt) {

$page_cnt = (int) (($imgcnt - 1) / (TABLE_COLS * TABLE_ROWS)) + 1;
return $page_cnt;
}

// *********************************************************************
?>


Here is the relevant code for the GetImageList() function



    function getImageList($gallerydir) {
if (isset($_POST['imglist'])) {
$imglist = $_POST['imglist'];
} else {
$fh = opendir("$gallerydir/thumbs");

// read directory, and loop through retreived filenames
while ($file = readdir($fh)) {
// if image, add filename to image list
if (!preg_match(".(jpg|gif|png|jpeg|jpe)$", $file)) {
$imglist = $file;
}
}
closedir($fh);
}

if (is_array($imglist)) {
ksort($imglist);
} else {
$imglist = false;
}
return $imglist;
}

//*********************************************************************
// Javascript writes image list as http posted array

function getJavaScript($imglist) {
$str = '
<script language="JavaScript">
function imgSubmit(s) {
document.img.method = "post";
document.img.action = s;
document.img.submit();
}

function imgList() {
';
$str .= "tvar imglist = new Array('" . implode("', '", $imglist) . "');n";
$str .= '
for (var i=0; i < imglist.length; i++) {
document.write ("<input type="hidden" name="imglist" ");
document.write ("value="" + imglist[i] + "" />");
}
}
</script>
';
return $str;
}

//*********************************************************************

?>






javascript php gallery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 18:19









Funk Forty Niner

1




1










asked Jan 2 at 7:58









Mark JMark J

12




12








  • 2





    You’re listing the contents of a directory somewhere and that contains also entries . and .. so you’ll have to filter those out

    – Sami Kuhmonen
    Jan 2 at 8:00











  • It's probably your getImageList() method that doesn't filter out the current (.) and parent (..) directory

    – kerbholz
    Jan 2 at 8:05











  • I've added the getImageList() function code to my question.

    – Mark J
    Jan 2 at 8:14











  • Thank you for the edits. I really appreciate it. Unfortunately it has yet to solve the problem. One thing I discovered was that all of the images available to the gallery are still being posted, the two pictures that don't work do not even exist and are addons to the total amount of images. Is it something in the for loop maybe?

    – Mark J
    Jan 3 at 1:15














  • 2





    You’re listing the contents of a directory somewhere and that contains also entries . and .. so you’ll have to filter those out

    – Sami Kuhmonen
    Jan 2 at 8:00











  • It's probably your getImageList() method that doesn't filter out the current (.) and parent (..) directory

    – kerbholz
    Jan 2 at 8:05











  • I've added the getImageList() function code to my question.

    – Mark J
    Jan 2 at 8:14











  • Thank you for the edits. I really appreciate it. Unfortunately it has yet to solve the problem. One thing I discovered was that all of the images available to the gallery are still being posted, the two pictures that don't work do not even exist and are addons to the total amount of images. Is it something in the for loop maybe?

    – Mark J
    Jan 3 at 1:15








2




2





You’re listing the contents of a directory somewhere and that contains also entries . and .. so you’ll have to filter those out

– Sami Kuhmonen
Jan 2 at 8:00





You’re listing the contents of a directory somewhere and that contains also entries . and .. so you’ll have to filter those out

– Sami Kuhmonen
Jan 2 at 8:00













It's probably your getImageList() method that doesn't filter out the current (.) and parent (..) directory

– kerbholz
Jan 2 at 8:05





It's probably your getImageList() method that doesn't filter out the current (.) and parent (..) directory

– kerbholz
Jan 2 at 8:05













I've added the getImageList() function code to my question.

– Mark J
Jan 2 at 8:14





I've added the getImageList() function code to my question.

– Mark J
Jan 2 at 8:14













Thank you for the edits. I really appreciate it. Unfortunately it has yet to solve the problem. One thing I discovered was that all of the images available to the gallery are still being posted, the two pictures that don't work do not even exist and are addons to the total amount of images. Is it something in the for loop maybe?

– Mark J
Jan 3 at 1:15





Thank you for the edits. I really appreciate it. Unfortunately it has yet to solve the problem. One thing I discovered was that all of the images available to the gallery are still being posted, the two pictures that don't work do not even exist and are addons to the total amount of images. Is it something in the for loop maybe?

– Mark J
Jan 3 at 1:15












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003003%2fphp-gallery-not-correctly-displaying-first-two-images-in-gallery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003003%2fphp-gallery-not-correctly-displaying-first-two-images-in-gallery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter