Results 1 to 3 of 3

Thread: lightbox/gallery miscounts photos in directory

  1. #1
    Join Date
    Jun 2008
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy lightbox/gallery miscounts photos in directory

    Hi everyone,

    A friend of mine has a photo gallery on his site, which is built with PHP (and I imagine the gallery also uses javascript). The gallery uses thumbnails, which are auto generated when you upload photos to specific locations (four total), then when you click on one, a lightbox popups up with a larger version. There are also 'back' and 'next' arrows along with a nav of sorts that says what photo you're on (5/6, 1/8, etc) If the photo folder on the server has more than four, the CMS prints a link that says "+5 more" or however many more in the thumbnail area. When you click that link, the lightbox appears, starting on the next photo in line.

    There are three problems. First, the thumbnail area always shows one less photo than what we actually uploaded. Second, the '+X more' link also miscounts the remaining photos after four (one less to be exact - same as the thumbnail display). Third, if I click on the 'more' link, the lightbox correctly counts the total number of photos, but the very last one generates a message - "'/var/www/html/mainFolderName/subFolderName/subSubFolderName' is not a file".

    Here is some of the code. Line 112 is where it starts to print the thumbnail div area; line 141 prints the actual thumb; line 150 prints the 'more' link; line 155 looks like it does something important, not sure what it is.

    PHP Code:

    #    # Only grab directories - Leave files alone
    #     #------------------------------------------ 
    # $s=1;
    # $anchor=1;
    # if (is_dir($npart)) {
    #  
    # $display_name = str_replace("_"," ",$npart);
    # $display_name = str_replace("DOT",".",$display_name);
    # $display_name = str_replace("APO","'",$display_name);
    #         print "     <div id='project_title'>".strtoupper($display_name)."</a></div><div id='project_thumbs'>";
    # $d = dir("$npart/");
    # $tb = 0;
    # while (false !== ($file = $d->read())) {
    #  
    #  
    # while (false !== ($file = $d->read())) {
    # if ($file != "." && $file != ".." && $file != ".DS_Store") { $tb++; }
    #  
    #  
    #  
    # if ($s < 5) {
    #     if ($file != "." && $file != ".." && $file != ".DS_Store") {
    #  
    #  
    #  
    # $size = getimagesize("$npart/$file");
    # $width = $size[0] + 75;
    # $height = $size[1] + 132;
    #  
    # print "<a  rel=\"gb_imageset[$display_name]\" title=\"$display_name\"  href='phpThumb.php?src=PROJECTS/$which_project/$npart/$file&w=800' rel='$npart'><img src=\"phpThumb.php?src=PROJECTS/$which_project/$npart/$file&w=78&h=48\" width=\"78\" height=\"48\"></a>";
    # $s++;       }
    #  
    #  
    # $anchor++;
    #  
    #     }
    # elseif ($s == 5) {
    #  
    # $more_link = "<BR><div style='position:relative; top:-68px; left:270px; display:inline; float:none; margin-bottom:-10px;'><a class='morelink' href='phpThumb.php?src=PROJECTS/$which_project/". $npart. "/" .$file. "&w=800' rel=\"gb_imageset[$display_name]\">";
    # $tb_links = "";
    # $s++;      
    #  
    # }      
    # elseif ($s > 5) { $tb_links = $tb_links . "<a style='display:none;' href='phpThumb.php?src=PROJECTS/$which_project/$npart/$file&w=800' rel=\"gb_imageset[$display_name]\" ></a>"; $s++; }
    #         $z++;  
    #        
    #     }
    #  
    #     }
    # $tb = $tb - 4;
    # if ($tb < 0) { $tb = 0; }
    # if ($tb > 0) { print $more_link."+ " . $tb . " more photos</a></div>"; print $tb_links;}
    #  
    #  
    # print "</div>";
    # } 
    Thanks much. I hope it's a simple bug. I'm a web developer but not a PHP programmer Let me know if you additional info.

    Sue
    Last edited by jscheuer1; 04-26-2009 at 03:07 PM. Reason: format to php

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    I don't know much about PHP, but after formating your above code with the forum's built in PHP highlighter, it's obvious that it's either all garbage, or all a comment, or perhaps some other language.

    There is a PHP script for grabbing image files from a folder and translating them into a javascript array here:

    http://www.dynamicdrive.com/dynamici...etpics.php.txt

    which is used by this script:

    http://www.dynamicdrive.com/dynamici...photoalbum.htm

    perhaps it will be of some help.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2008
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Sorry about that; maybe I should have posted all the code from the php file. It follows (and is attached):

    Code:
    <? $section = "projects"; ?>
    <? if (isset($_GET['subsection'])) { $subsection = $_GET['subsection']; } else { $subsection = "commercial"; } ?>
    <? include ('includes/header.php'); ?>
       <script type="text/javascript">
            var GB_ROOT_DIR = "./greybox/";
        </script>
    
        <script type="text/javascript" src="greybox/AJS.js"></script>
        <script type="text/javascript" src="greybox/AJS_fx.js"></script>
        <script type="text/javascript" src="greybox/gb_scripts.js"></script>
        <link href="greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all" />
    
    <style type="text/css">
    #linksV { width:107px; overflow:hidden; }
    #linksV a, #linksH a	{
    	position:relative; 
    	display: block;
    	width: 107px;
    	line-height: 13px;
    	min-height: 13px;
    	text-decoration: none;
    	font-size:10px;
    	font-family:Arial, Helvetica, sans-serif;
    	color:#ffffff;
    	margin-bottom:13px;
    	letter-spacing:1px;
    	
    	}
    #linksV a	{
       color: ffffff;
       background: url(images/subnav_bg_off.png) no-repeat;
       }
    
    #linksV a:visited  {
       }
    
    #linksV a:hover, #linksV a.on {
       background: url(images/subnav_bg_on.png) no-repeat;
       color:#ed1c24;   
       }	
     #project_title { margin-top:15px; letter-spacing:1px; margin-left:5px; margin-bottom:5px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#ffffff; text-align:left; width:366px; }
     #project_thumbs { text-align:left; width:366px;  height:50px; }
     #project_thumbs img { display:inline; margin-left:8px; width:78px; height:48px; }
    
     #project_thumbs a:hover{
    		color:#ed1c24;
    	}
    	 #project_thumbs a:link img,
    	 #project_thumbs a:visited img{
    		border:1px solid #433c3a;
    	}
    	 #project_thumbs a:focus img,
    	 #project_thumbs a:hover img,
    	 #project_thumbs a:active img{
    		border:1px solid #ed1c24;
    	}
    a.morelink, a.morelink:visited, a.morelink:active { font-size:10px; color:#ffffff; font-family:Arial, Helvetica, sans-serif; }
    </style>
    <!--[if IE]>
    <style type="text/css" media="screen">
    	#linksV a, #linksH a	{
    		width: 125px;
    		}
    #project_thumbs { margin-bottom:-10px; }
    </style>
    <![endif]-->
    
    <table width="800" cellpadding="0" cellspacing="0" border="0">
    	<tr>
    		<td style="width:107px; vertical-align:top; padding-top:35px; text-align:left;" id="leftnav">
    		<div id="linksV"><!--
    		--><a href="?subsection=commercial" <? if ($subsection == "commercial") echo "class='on'"; ?>>&nbsp;&nbsp;COMMERCIAL</a><!--
    		--><a href="?subsection=residential" <? if ($subsection == "residential") echo "class='on'"; ?>>&nbsp;&nbsp;RESIDENTIAL</a><!--
    		--><a href="?subsection=educational" <? if ($subsection == "educational") echo "class='on'"; ?>>&nbsp;&nbsp;EDUCATIONAL</a><!--
    		--><a href="?subsection=community" <? if ($subsection == "community") echo "class='on'"; ?>>&nbsp;&nbsp;COMMUNITY</a><!--
    		--></div>
    		</td>
    		<td style="width:322px; vertical-align:top; background:url('images/projects_<?= $subsection; ?>_image.jpg') top center no-repeat;"></td>
    		<td style="width:366px; height:500px; vertical-align:top; color:#ffffff;" id="thumbs"><div style="position:relative;">
    <? 
    # Read the directory
    #-------------------
    chdir( './PROJECTS' );
    $which_project = strtoupper($subsection); 
    chdir ( './'.$which_project.'');
    
    $dir="./"; 
    if (is_dir($dir)) {   
       $fd = @opendir($dir);   
          while (($part = @readdir($fd)) == true) {   
             if ($part != "." && $part != "..") {   
                $file_array[]=$part; 
             }   
          }   
          if ($fd == true) {   
             closedir($fd);   
          } 
       }
    
    # Sort the directory alphabetically
    #----------------------------------
    sort($file_array); 
    reset($file_array); 
    if (count($file_array) < 1) echo "<p style='margin:10px; font-family:arial; font-size:11px;'>No Current Projects Available to Display</p>";
    
    for($i=0;$i<count($file_array);$i++) { 
    	$npart=$file_array[$i]; 
     	$fsize=filesize($npart); 
     
     	
     	# Only grab directories - Leave files alone
     	#------------------------------------------	
    $s=1;
    $anchor=1;
    if (is_dir($npart)) {
    
    $display_name = str_replace("_"," ",$npart);
    $display_name = str_replace("DOT",".",$display_name);
    $display_name = str_replace("APO","'",$display_name);
    		print "		<div id='project_title'>".strtoupper($display_name)."</a></div><div id='project_thumbs'>";
    $d = dir("$npart/");
    $tb = 0;
    while (false !== ($file = $d->read())) {
    
    
    while (false !== ($file = $d->read())) {
    if ($file != "." && $file != ".." && $file != ".DS_Store") { $tb++; }
    
    
    
    if ($s < 5) {
    	if ($file != "." && $file != ".." && $file != ".DS_Store") {
    
    
    
    $size = getimagesize("$npart/$file");
    $width = $size[0] + 75;
    $height = $size[1] + 132;
    
    print "<a  rel=\"gb_imageset[$display_name]\" title=\"$display_name\"  href='phpThumb.php?src=PROJECTS/$which_project/$npart/$file&w=800' rel='$npart'><img src=\"phpThumb.php?src=PROJECTS/$which_project/$npart/$file&w=78&h=48\" width=\"78\" height=\"48\"></a>";
    $s++;		}
    
    
    $anchor++;
    
    	}
    elseif ($s == 5) {
    
    $more_link = "<BR><div style='position:relative; top:-68px; left:270px; display:inline; float:none; margin-bottom:-10px;'><a class='morelink' href='phpThumb.php?src=PROJECTS/$which_project/". $npart. "/" .$file. "&w=800' rel=\"gb_imageset[$display_name]\">";
    $tb_links = "";
    $s++;		
    
    }		
    elseif ($s > 5) { $tb_links = $tb_links . "<a style='display:none;' href='phpThumb.php?src=PROJECTS/$which_project/$npart/$file&w=800' rel=\"gb_imageset[$display_name]\" ></a>"; $s++; }
    		$z++;  
    		
    	}
     
    	}
    $tb = $tb - 4;
    if ($tb < 0) { $tb = 0; }
    if ($tb > 0) { print $more_link."+ " . $tb . " more photos</a></div>"; print $tb_links;} 
    
    
    print "</div>";
    }
    
    } 
    chdir ( '../../');
    
    ?> 
    		<p style="height:10px; margin-bottom: 0;"></p></div></td>
    	</tr>
    </table>
    <? include ('includes/footer.php'); ?>
    Thanks again.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •