0

Photo Gallery Code.

This code is show all the images from the images folder with filename ending with "_thumb"

When i run this code its working but i a getting an error as "Notice: Undefined variable: count in C:\wamp\www\photogallery\AutoGeneratingGallery\index.php on line 58"

I am using Wamp server 2.0 Please some help me to solve this issue.

<?php
		
		/* settings */
		$image_dir = 'images/';
		$per_column = 5;
		
		
		/* step one:  read directory, make array of files */
		if ($handle = opendir($image_dir)) {
			while (false !== ($file = readdir($handle))) 
			{
				if ($file != '.' && $file != '..') 
				{
					if(strstr($file,'-thumb'))
					{
						$files[] = $file;
					}
				}
			}
			closedir($handle);
		}
		
		/* step two: loop through, format gallery */
		
			
		if(count($files))
		{
			$count++;
			foreach($files as $file)
			{
				
				echo '<a class="photo-link" rel="one-big-group" href="',$image_dir,str_replace('-thumb','',$file),'"><img src="',$image_dir, $file,'" width="100" height="100" /></a>';
				if($count % $per_column == 4) 
				{ 
				echo '<div class="clear"></div>'; 
				}
			}
		}
		else
		{
			echo '<p>There are no images in this gallery.</p>';
		}
		
	?>

Edited by anoopkris123: allignment

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by richieking
0

This code is running fine in my server.
Try declaring the '$count=0' before and increment it in the loop.
May that work.
Good luck

0

use error_reporting(E_ALL & ~E_NOTICE); for avoid notice

This notice is generated due to the value is not assigned to that variable.

Enjoy!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.