hi add one if condition to check . and .. like this
while (($file = readdir($dh)) !== false) {
if($file != '.' && $file != '..'){
$display_models .= '<li><a href="#"><img src="'.$dir.'/'.$file.'"></a></li>';
}
}
check this tutorial can also help you scanning folder with php