954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Urgent requirement of image gallery in php

hello...

Can any one please help me out?
I want an image gallery script, where the images are displayed as thumbnails from many subfolders created dynamically and not from database...

Thanks in Advance...

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

Please check out this url:
http://mig.sourceforge.net/gallery/index.php?currDir=.

And i want to implement my galley in this way..
Please post me any information.

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

Please help me....

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

Once Check my thread and reply..
please.....

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

i have done this before for someone on daniweb. search through old threads and you should find something that can help you.

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

Hello keith...
Thanks for your reply...
I have reffered all your old posts...
But i found nothing according to my requirement...
I think you have enough knowledge to clear my thread...
Please help...

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

Hi Shanti,

It was a nice idea, so I worked on it and came with this. This will help you.

<style>
	td{font: 12px Arial; color: #333333;}
</style>

<script language=javascript>
	function clicked(val)
	{
		location.href = "rec_dir_list.php?dir="+val;
	}
</script>

<html>
<title>Foto Album</title>
<body>
<?php
//level variable will hold 1 or 0, depending on if the directory has only files.
//1 - if sub-folders are still there
//0 - if only image files are there.

function list_images($imgdir,$level)
{
	//$imgdir = './images/'; // the directory, where your images are stored
	$allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes you want to show
	$dimg = opendir($imgdir);
	$imgfile = readdir($dimg);
	while($imgfile = readdir($dimg))
	{
			
	 	if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
		{
			$a_img[] = $imgfile;
			sort($a_img);
			reset ($a_img);
		} 
	}
	$totimg = count($a_img); // total image number
	if($totimg > 0)
	{
		echo '<center><table><tr>';
		for($x=0; $x < $totimg; $x++)
		{
			$size = getimagesize($imgdir.'/'.$a_img[$x]);
			$halfwidth = ceil($size[0]/4);
			$halfheight = ceil($size[1]/4);
			if($x % 4 == 0 && $x != 0)
			{
				echo '</tr><tr>';
			}
			echo '<td><table border=1><tr><td><img src="'.$imgdir.'/'.$a_img[$x].'" width='.$halfwidth.' height='.$halfheight.'></td></tr></table></td>';
			if($level==1)
			{
				break;
			}
		}
		if($totimg%4 == 0)
		{
			echo '</table>';
		}
		else
		{
			echo '</tr></table>';
		}	
	}
	else
	{
		echo '<center><table><tr><td>No Images found</td></tr></table>';	
	}	
}

function recur_dir($dir)
{
	$flag=0;$ind=1;
	$dirlist = opendir($dir);
	echo '<center><table bgcolor=#eeeeee width="30%"><tr>';
	while ($file = readdir ($dirlist))
	{
		if ($file != '.' && $file != '..')
		{
			$newpath = $dir.'/'.$file;
			$level = explode('/',$newpath);
			if (is_dir($newpath))
			{
				$ind += 1;
				$flag = 1;
				echo "<td>";
				echo '<center><table><tr><td>';
				list_images($dir.'/'.end($level),1);
				echo '</td></tr><tr><td align=center>';
				echo '<a href=javascript:clicked("'.$dir.'/'.end($level).'")>'.end($level).'</a>';								
				echo '</td></tr></table>';
				echo "</td>";
			}
		}
		
	}
	if($flag==0)
	{
		echo "<td>";
		list_images($dir,0);
		echo "</td></tr><tr><td><hr>Current Dir: ". $dir;
		echo "</td></tr></table>";
	}
	else
	{
		echo "</tr><tr><td colspan=".$ind." align=center><hr>Current Dir: ". $dir;
		echo "</td></tr></table>";
	}
	closedir($dirlist); 
	

}
$curr_dir = $_REQUEST['dir'];
if($curr_dir == "")
{
	$curr_dir = './images';
}
recur_dir($curr_dir);
?>
</body>
</html>
vicky_rawat
Junior Poster
137 posts since Jun 2008
Reputation Points: 28
Solved Threads: 19
 

Thanks vivek...
I will have a look..

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

hi vivek,
i tried ur code and i am getting error
Notice: Undefined index: dir in D:\www\arya\images.php on line 113
in this line $curr_dir = $_REQUEST['dir'];
could u help me
thanks in advance

praveen_dusari
Posting Whiz in Training
204 posts since Jun 2008
Reputation Points: 21
Solved Threads: 29
 

vicky's code is fantastic

just comment out line 22 and create a directory 'images' after that store some images in it

nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
 

thanks for reply nil,i have done that but still iam getting error
thanks in advance

praveen_dusari
Posting Whiz in Training
204 posts since Jun 2008
Reputation Points: 21
Solved Threads: 29
 

its just a notice not an error. the script should still work. just change your error reporting to not show notices.

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

i got this error:
Notice: Undefined index: dir in imggallery.php on line 112
$curr_dir = $_REQUEST['dir'];

Sanjay Sahu
Newbie Poster
5 posts since Jul 2008
Reputation Points: 11
Solved Threads: 1
 
Sanjay Sahu
Newbie Poster
5 posts since Jul 2008
Reputation Points: 11
Solved Threads: 1
 

Hi Friends,

Good news, I have modified the script somewhat more.now it supports
1. moving in directory ans subdirectories.
2. moving up the directory
3. slide show of the images.

just edit the following code and replace the "images" with the directory you want your photo album to start with.

if($curr_dir == "")
{
	$curr_dir = 'images';
}


Cheers.

Attachments photoalbum.php (3.46KB) disp_image.php (1.22KB)
vicky_rawat
Junior Poster
137 posts since Jun 2008
Reputation Points: 28
Solved Threads: 19
 


<?php
//level variable will hold 1 or 0, depending on if the directory has only files.
//1 - if sub-folders are still there
//0 - if only image files are there.

function list_images($imgdir,$level) { $imgdir = 'images/'; // the directory, where your images are stored $allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes you want to show $dimg = opendir($imgdir); $imgfile = readdir($dimg); while($imgfile = readdir($dimg)) { if(in_array(strtolower(substr($imgfile,-3)),$allowed_types)) { $a_img[] = $imgfile; sort($a_img); reset ($a_img); } } $totimg = count($a_img); // total image number if($totimg > 0) { echo ''; for($x=0; $x < $totimg; $x++) { $size = getimagesize($imgdir.'/'.$a_img[$x]); $halfwidth = ceil($size[0]/4); $halfheight = ceil($size[1]/4); if($x % 4 == 0 && $x != 0) { echo ''; } echo ''.$a_img[$x].''; if($level==1) { break; } } if($totimg%4 == 0) { echo ''; } else { echo ''; } } else { echo 'No Images found'; } }

function recur_dir($dir)
{
$flag=0;$ind=1;
$dirlist = opendir($dir);
echo '';
while ($file = readdir ($dirlist))
{
if ($file != '.' && $file != '..')
{
$newpath = $dir.'/'.$file;
$level = explode('/',$newpath);
if (is_dir($newpath))
{
$ind += 1;
$flag = 1;
echo "";
echo '';
list_images($dir.'/'.end($level),1);
echo '';
echo ':clicked("'.$dir.'/'.end($level).'")>'.end($level).'';
echo '';
echo "";
}
}

}
if($flag==0)
{
echo "";
list_images($dir,0);
echo "Current Dir: ". $dir;
echo "";
}
else
{
echo "Current Dir: ". $dir;
echo "";
}
closedir($dirlist);

}
$curr_dir = $_REQUEST['dir'];
if($curr_dir == "")
{
$curr_dir = './images';
}
recur_dir($curr_dir);
?>

nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
 

Hi Nil,

Can you please let me know, what modificatio you have made.

I think you uncommented the following line

$imgdir = 'images/'; // the directory, where your images are stored


if yes, then this will make this code to work in only one level.
I have made this script to work in more then one levels.

vicky_rawat
Junior Poster
137 posts since Jun 2008
Reputation Points: 28
Solved Threads: 19
 

hi vicky sorry for trouble,
i have a images in 'images folder' and images2
as sub folder when i click on sub folder iam getting images in actual 'imagesfolder'
thanks again

praveen_dusari
Posting Whiz in Training
204 posts since Jun 2008
Reputation Points: 21
Solved Threads: 29
 

Hi Shanti,

I have included the files that matches exactly your requirements in my earlier posts.

vicky_rawat
Junior Poster
137 posts since Jun 2008
Reputation Points: 28
Solved Threads: 19
 

Hi Shanti,

I have included the files that matches exactly your requirements in my earlier posts.


Its gud..
Very thanks for your time...

But i got this error..
Notice: Undefined variable: a_img in E:\web\test\photoalbum.php on line 39

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You