Location: PHPKode > scripts > Image Processor and Watermarker > image-processor-and-watermarker/DisplayImageDir.class.php
<?php
// php_include/classes/DisplayImageDir.class.php
 

class DisplayImageDir{
	
var $linkToSubDirs ;
	
	
	
	
function __construct($dir='' ){
if($dir !='')
	$dir = getcwd();
$this->linkToSubDirs =1;

//change this to the location of where you're outputing your files using the Image
$rootURl='http://' . $_SERVER['HTTP_HOST'] . '/';


$imageViewerUrl = 'view.php5';



$folder = opendir($dir); // Use 'opendir(".")' if the PHP file is in the same folder as your images. Or set a relative path 'opendir("../path/to/folder")'.

 

$pic_types = array("jpg", "jpeg", "gif", "png");

 

$picsArr = array();
$dirsArr = array();


//can't inclde document root in name...need url
$startIndex =  strlen($_SERVER['DOCUMENT_ROOT']   ) ;

while ($file = readdir ($folder)) 
	{

		if(in_array(substr(strtolower($file), strrpos($file,".") + 1),$pic_types))
		{
		$pic= substr($dir, $startIndex) . '/'.$file;
		array_push($picsArr,$pic);
		}
	else if ($this->linkToSubDirs ===1 && is_dir($file) && $file !='.' && $file != '..' )
		array_push($dirsArr ,substr($dir, $startIndex) . '/'. urlencode($file  ) );				

	}
closedir($folder);

echo '<a name="t"></a>';

if(count($dirsArr ) >0)
	foreach($dirsArr  as $d)
	echo '<a href="' . $rootURl .$d . '">'.$d.' </a><br />';

echo '<table border="1"><tr><td>';

echo '<a   href="'. $imageViewerUrl. '?img='.   $picsArr[0]  . '" target="_blank"><img hspace="5" vspace= "5" src="'.  $imageViewerUrl. '?img='.   $picsArr[0]  . '" />  </a></td></td><td> 
<script type="text/javascript"><!--
google_ad_client = "pub-1577838290985250";
/* 300x250, created 12/12/09 */
google_ad_slot = "5879593532";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></td></tr>';

$count=0;
//foreach($picsArr as $pic)
for($i= 1; $i< count($picsArr ) ;$i++)
{//s/

		$pic = $picsArr[$i];
	if($i ==  5 ){
	 	echo'<tr><td> 
<script type="text/javascript"><!--
google_ad_client = "pub-1577838290985250";
/* 300x250, created 12/12/09 */
google_ad_slot = "5879593532";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></td><td></td></tr>';


	}
if($count % 2 ==0)
		echo '<tr>';
	//echo   $pic  . '<br />';
	$url =  $imageViewerUrl. '?img='.   $pic ;
	echo '<td><a title="Picture  '. ++$count .  '" href="'. $url . '" target="_blank"><img hspace="5" vspace= "5" src="'. $url . '" />  </a></td>';
		if($count % 2 ==0)
		echo '</tr>';
	}

 
 
 
if($count % 2 !=0 )
	echo '<td>&nbsp;</td></tr>';
	
	
		echo '</table><a href="#t">Top</a>';
}
	
	
	
	
	
	
}
 
 
 
?>
Return current item: Image Processor and Watermarker