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>';
		}
		
	?>

Recommended Answers

All 3 Replies

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

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!

declare

$count=0; or $count; on line 25.

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.