All pastes #205456 Raw Edit

seanferd

public text v1 · immutable
#205456 ·published 2006-10-16 20:47 UTC
rendered paste body
	$dirs = array();
	$file = '';
	$handle = '';
	//this will probably have to become a function with the way it's going..
	if( $handle = opendir('images/thumbs') ) {
		$i = 0;
		while(( $file = readdir( $handle )) !== false ) {
		   
		   if( strpos( $file, '.' ) ) { //makes sure you get a .jpg instead of a directory
			   $file = htmlspecialchars( $file );
			   echo( "<a href='images/pics/" . $file . "'><img src='images/thumbs/" . $file . "' alt='" . $file . "'/></a>\n" );
		   } else {
			   $dirs[$i] = $file;
		   }
		   $i++;
		}
		closedir( $handle );
		$file = '';
		$i = 0;
		
		//this gets all the folders the initial one didn't and parses out . and .. 
		foreach( $dirs as $dir ) {
			echo( $dir );
 			if( $dir != '.' && $dir != '..' ) { //hopefully prevents recursion.... maybe think about using is_dir()? 				
				if( $handle = opendir( 'images/thumbs/' . $dir ) ) {					
					while(( $file = readdir( $handle )) !== false ) {						
					   if( strpos( $file, '.' ) ) {						   
						   $file = htmlspecialchars( $file );
						   /* echo( $dir . $file ); */
						   echo( "<a href='images/pics/" . $file . "'><img src='images/thumbs/" . $file . "' alt='" . $file . "'/></a>\n" );						   
					   }					   
					}					
				}				
			}
			$i++;
		}
	}
	closedir( $handle );
	$dirs = '';
	$file = '';