• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

Tweaking a php code for photo gallery

I have written this code (from a tutorial) to display a photo gallery from a directory using lightbox. It works amazing so far. The only complaint I have is it has an in between page that I don't like. Right now it navigates to a page where you select an album that you would like to view. shows direct
Above shows that it first displays a list of photo galleries. After you click it navigates to the gallery selected and displays the photos. The galleries are sorted by folder on my site.

my gallery
So what I want is to skip the showing of the directory like in the first photo and go directly to the gallery. I plan on just having one two folders named photogallery and thumbs in my data folder. Can anyone change to part in my code to skip directly to the gallery.

Thanks, let me know if you need any additional information.
Here is my code

<?php


$page = $_server['php_self'];


//settings
$column = 9;

//directories

$base = "data";
$thumbs = "thumbs";

//get album
$get_album = $_GET['album'];

if (!$get_album)
{
	echo "<b>select an album: </b><p />";	
	$handle = opendir($base);
	while (($file = readdir($handle))!==FALSE)
	{
	if (is_dir($base."/".$file) && $file !="." && $file !=".." && $file !=$thumbs)
		
		{
		echo "<a href='$page?album=$file'>$file</a><br />";	
		}
	}
	closedir($handle);
} 

		else
			{
			if (!is_dir($base."/".$get_album) || strstr($get_album,".")!=NULL || strstr($get_album,"/")!=NULL || strstr($get_album,"\\")!=NULL)
				
				
				{
					
				echo "album doesn't exist, please contact kora@kphoto-design.com";
				
				} 
				
				else 
					{
					$x = 0;
						
					echo "<b>$get_album</b><p />";
					$handle = opendir($base."/".$get_album);
					while (($file = readdir($handle)) !==FALSE)
						{
						if ($file != "." && $file !="..")
								{
								echo "<a href='$base/$get_album/$file' rel='example_group' title='Image: $file'>
								<img src='$base/$thumbs/$file' height='100' width='100'>";
								$x++;
								
								if ($x==$column)
								{
								echo "<br />";
								$x = 0;
								}
								}
						}
						
			closedir($handle);
			
			echo "<p /><a href='index.php'>Back to your albums.</a>";
					
					}

			
			}



	
?>

Open in new window

0
Pancake_Effect
Asked:
Pancake_Effect
1 Solution
 
Erdinç Güngör ÇorbacıPHP Development Team LeaderCommented:
try this ;

<?php

$skip_album_selection=TRUE;
$default_album_folder="";//You can write first opened album here

$page = $_server['php_self'];


//settings
$column = 9;

//directories

$base = "data";
$thumbs = "thumbs";

//get album
$get_album = $_GET['album'];

if (!$get_album && $skip_album_selection==FALSE)
{
	echo "<b>select an album: </b><p />";	
	$handle = opendir($base);
	while (($file = readdir($handle))!==FALSE)
	{
	if (is_dir($base."/".$file) && $file !="." && $file !=".." && $file !=$thumbs)
		
		{
		echo "<a href='$page?album=$file'>$file</a><br />";	
		}
	}
	closedir($handle);
} 
elseif($skip_album_selection==TRUE){

	$handle = opendir($base);
	while (($file = readdir($handle))!==FALSE)
	{
		if (is_dir($base."/".$file) && $file !="." && $file !=".." && $file !=$thumbs){
			if($default_album_folder!=""){
				if($file==$default_album_folder) {
					$get_album=$file;	
				}
			}
			
			if(!$first_album) $first_album=$file;
		}
	}
	if(!$get_album && $first_album) $get_album=$first_album;
	closedir($handle);
}


		if($get_album)
			{
			if (!is_dir($base."/".$get_album) || strstr($get_album,".")!=NULL || strstr($get_album,"/")!=NULL || strstr($get_album,"\\")!=NULL)
				
				
				{
					
				echo "album doesn't exist, please contact kora@kphoto-design.com";
				
				} 
				
				else 
					{
					$x = 0;
						
					echo "<b>$get_album</b><p />";
					$handle = opendir($base."/".$get_album);
					while (($file = readdir($handle)) !==FALSE)
						{
						if ($file != "." && $file !="..")
								{
								echo "<a href='$base/$get_album/$file' rel='example_group' title='Image: $file'>
								<img src='$base/$thumbs/$file' height='100' width='100'>";
								$x++;
								
								if ($x==$column)
								{
								echo "<br />";
								$x = 0;
								}
								}
						}
						
			closedir($handle);
			
			echo "<p /><a href='index.php'>Back to your albums.</a>";
					
					}

			
			}



	
?>

Open in new window

0
 
Pancake_EffectAuthor Commented:
Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now