Updating Gallery Content using POST

I’m trying to make an update-able gallery. The navigation bar consists of a simple form which uses php to build a drop-down list of directories (gallery names). When the user clicks on one, it shows the contents as a new gallery.

It sort of works. HOWEVER, only the original gallery works as a clickable thumbnail that generates the correct main image. I keep running into three different problems:

  1. The correct gallery shows, but the $now_viewing variable doesn’t seem to take. For example, if I’ve clicked gallery_B and it looks right, I click one of its thumbnails, and the error says “function getimagesize[] link/gallery_A/$main_image”. No such file or directory.
  2. Otherwise, if it reads the correct gallery, say gallery_c, then the error reads “function getimagesize[] link/gallery_c/image_from_gallery_A. No such file or directory”
  3. Last, when I click around on the original, refreshed page gallery (using the default dir), it works fine. HOWEVER, I’m unable to choose a new gallery after clicking around, because the $_GET information is in the address bar. But, if I refresh, then I lose the $_POST $variable, and return to default.

I think the answer is in turning this into several pages. But, not sure how just yet…If anyone can help, I’ll tell Santa to treat you right this year.

[php]<?php
if (! @include(‘connection’)) {
echo ‘Sorry, the database is unavailable’;
exit;
}
define(‘COLS’,3);
define(‘GALMAX’,9);
$conn = //connect;
if (array_key_exists(‘selectDir’,$_POST)) {
$now_viewing = $_POST[‘directory’];
$SESSION[‘now_viewing’] = $now_viewing;
// $gallery_title = str_replace(’
’,’ ‘,$now_viewing);
$getTotal = “SELECT COUNT() FROM sale_items WHERE gallery_name = ‘$now_viewing’";
$total = mysql_query($getTotal);
$row = mysql_fetch_row($total);
$total_images = $row[0];
//set current page
$curPage = isset($_GET[‘curPage’])? $GET[‘curPage’]:0;
$startRow = $curPage * GALMAX;
$sql = “SELECT * FROM sale_items WHERE gallery_name = ‘$now_viewing’”.“LIMIT $startRow,”.GALMAX;
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
}
elseif (!$POST)) {
//or else scan the directory, and show the first item
$contents = scandir(‘main_directory’);
$found = array();
foreach ($contents as $item) {
$DirInfo = pathinfo($item);
if(array_key_exists(‘dirname’,$DirInfo) && !array_key_exists(‘extension’,$DirInfo)) {
$found[] = $item;
}
}
if ($found) {
natcasesort($found);
foreach($found as $dirname) {
$now_viewing = str_replace(’
’,’ ‘,$found[1]);
}
}
// $gallery_title = str_replace(’
’,’ ',$now_viewing);
$getTotal = "SELECT COUNT(
) FROM sale_items WHERE gallery_name = ‘$now_viewing’”;
$total = mysql_query($getTotal);
$row = mysql_fetch_row($total);
$total_images = $row[0];
//set current page
$curPage = isset($_GET[‘curPage’])? $_GET[‘curPage’]:0;
$startRow = $curPage * GALMAX;
$sql = “SELECT * FROM sale_items WHERE gallery_name = ‘$now_viewing’”.“LIMIT $startRow,”.GALMAX;
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
}
//find a default main image to display
if (isset($_GET[‘image’])) {
$mainImage = $_GET[‘image’];
}
else {
$mainImage = $row[‘filename’];
}
$imageSize = getimagesize(’…/directory_handle/’.$now_viewing."/$mainImage");
?>

Upcoming Sales

See Other Sale <?php //other items are built from here include('../../includes/BuildDirListFunction'); buildDirList ('/path/'); ?>

            <input name="selectDir" id="selectDir" type="submit" value="Go" />
            </p>
     </form>
  </div>
  
  
  <div id="Crumbs_Right">
        <p>Displaying <?php echo $startRow+1;
		if ($startRow+1 < $total_images) {
			echo ' to ';
			if ($startRow+GALMAX < $total_images) {
			echo $startRow+GALMAX;
		}
		else {
			echo $total_images;
		}
		}
		echo " of $total_images";
		?>
	</div>
  <div id="Crumbs_Right">
     <?php
     	if($curPage > 0) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'">&lt;&lt; Prev</a>';
		}
		else {
			echo '&nbsp';
		}
	 ?>
     &nbsp;
     <?php
	 //forward link
	 if($startRow+GALMAX < $total_images) {
		 echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'"> Next &gt;&gt;</a>';
	 }
	 else {
		 echo '&nbsp';
	 }
	 ?>
	 </p>
  </div>
  
</div><!----------------END <GalleryNav-->
    
  <div id="Thumbs">
    <table>
     <tr>
     <?php
	 //count
	 $pos = 0;
	 do { 
	 ?>
       <td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?image=<?php echo $row['filename']; ?>&amp;curPage=<?php echo $curPage; ?>"><img src="gallery_path/<?php echo $now_viewing."/thumbs/".$row['filename']; ?>" alt ="<?php echo $row['filename']; ?>"  /></td>
       <?php
	   $row = mysql_fetch_assoc($result);
	   $pos++;
	   //if at end of row, insert tags as needed
	   if ($pos%COLS === 0 && is_array($row)) {
		   echo '</tr><tr>';
	   }
	 } while ($row);
	 //new loop for final row
	 while ($pos%COLS) {
		 echo '<td>&nbsp;</td>';
		 $pos++;
	 }
	 ?>
     </tr>
    </table>
  </div>

<div class="MainImage">
	<img src="../path_info/<?php echo $now_viewing."/$mainImage"; ?>" alt="" <?php echo $imageSize[3]; ?>/>
</div><!--END <MainImage-->
  <div class="GalleryNav">

  <div id="Crumbs_Left">
     <p>Displaying item x of y</p>
  </div>
  <div id="Crumbs_Right">
     <p id="Crumbs_Right"><< Previous &nbsp; &nbsp;Next >></p>
  </div>
  
</div><!--END <GalleryNav-->
[/php]

UPDATE:
It dawned on me to if(array…‘directory’,$_POST)…unset($_GET). Now my only problem is that the $now_viewing variable doesn’t remain as $_POSTed when one clicks on a gallery thumbnail other than the default. For example Gallery2 thumb click = "handle/Gallery_1/correct_filename.

I’ve tried storing the $_POST variable as a $_SESSION variable. But, no comply…
…anybody?

Why don’t you comment bits and pieces of code . . . otherwise you may need to do mysql_fetch_array()?

Sponsor our Newsletter | Privacy Policy | Terms of Service