<?php 
$dirMenu = 'infraimage';
global $cnt;
$cnt = 0;

if (file_exists($dirMenu)) {
	$cnt =recurseDir($dirMenu); 
}

 function recurseDir($dir){
$cnt++;
	$all = "";
	if(is_dir($dir)){
		if($dh = opendir($dir)){
			while(($file = readdir($dh)) != false){
				if($file != '.' && $file != '..' && $file != 'Thumbs.db' && $file != 'thumbs.db' ){
					 if(!is_dir($dir."/".$file)){
							$src_dims = getimagesize($dir."/".$file);
						 $image_type = $src_dims[2];

						if( $image_type == IMAGETYPE_JPEG || $image_type == IMAGETYPE_GIF || $image_type == IMAGETYPE_PNG || $image_type == IMAGETYPE_BMP ) {
							$ext = substr($file,0,2);
						
							if($ext != "m_" && $ext != "t_")
							{
								unlink ($dir."/".$file);
							}
						}
					}
					else
					{
					
						$cnt2 = recurseDir($dir."/".$file);
						$cnt += $cnt2;
						
					}
				}
			}
		}
		closedir($dh); 
		echo $dir. " Cleared.<br/>";  
		
		return $cnt;    
	}
}
echo $cnt ." folders Cleared."; 
?>