Intendi questo?
<?
$cartella = $_POST['cartella'] ;
$f = fopen("$cartella.html","w+");
fputs($f,' \\codice html\\$folder = opendir($cartella) ;
while ($file = readdir($folder)) {
$array_file[] = $file;
}
foreach ($array_file as $file) {
echo "<tr><td><center>";
if ( $file == ".." || $file == ".") {
continue;
}

echo "$file";
echo "</tr></td></center>";
}
');
fclose($f);
?>

non funziona neanche così