Prueba asi:
Código PHP:
<?php
$variable = 0;//seteamos a 0 el sumador
$valor = 5;//seteamos a 6 las imagenes a mostrar por cada linea
echo "<table><tr>";
$directorio = opendir("img/");
while($archivo = readdir($directorio))
{
$nombreArch = str_replace("", "Atras", ucwords($archivo));
if($variable > $valor){ echo "<tr>";
}
echo "<td width='' height=''><a href='img/$archivo'>";
echo "<img src='img/$archivo' width='140' height='110'";
echo " border=0>";
echo "";
if($variable >= $valor){// si es mayor o igual añadimos </TR>
echo "</tr>";
$variable = 0;//seteamos a 0 el sumador y volvemos a empezar si quedan mas imagenes
}//end if
$variable++;//empezamos a sumar +1
}//end while
closedir($directorio);
echo "</tr></table>\n";
?>