Prova così:


$cartella = $_POST['cartella'] ;
$folder = opendir($cartella) ;
while ($file = readdir($folder))
{
if ( $file != ".." && $file != ".")
{
$array_file[] = $file;
}

}

$contenuto_cartella = ""; // stringa per il display html

if (is_array(array_file) && count(array_file) > 0)
{// se la cartella non è vuota
foreach ($array_file as $file)
{
$contenuto_cartella .= "<tr><td><center>";
$contenuto_cartella .= $file;
$contenuto_cartella .= "</tr></td></center>";
}
}



$cartella = $_POST['cartella'] ;
$f = fopen("$cartella/$nomefile.html","w+");
fputs($f,'codice html');
fputs($f,$contenuto_cartella);
fclose($f);


Ciao