C'è una svista in tutti e due i codici (HTML e PHP)
Codice HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="AlterVista - Editor HTML"/>
<title>spazio utenti</title>
</head>
<body>
<form action="nuovo_progetto.php" method="post">
<label>Nome file :
<input type="text" name="namefile" /></label><br>
<label> Testo :
<input type="text" name="text" /></label><br>
<input type="submit" value="Crea">
</form>
</body>
</html>
Codice PHP:
<?php
header('Content-type: text/html; charset=utf-8');
// Mostra un messaggio d'errore se mancano dei dati
if(!isset($_POST['namefile'], $_POST['text'])) {
die("<html>
<head>
<title>errore dati</title>
</head>
<body>Mancano alcuni dati</body>
</html>");
}
// Elabora i dati ricevuti
$esito = "file non creato";
$namefile = $_POST['namefile'];
$text = $_POST['text'];
$path = $namefile.".html";
$code = "<html>
<head>
<title>{$namefile}</title>
</head>
<body>{$text}</body>
</html>";
// Genera il file HTML
if(file_put_contents($path, $code) != 0) {
$esito = "file creato";
}
echo "<html>
<head>
<title>View result</title>
</head>
<body><pre>{$esito}
{$path}
".htmlentities($code, ENT_COMPAT, "UTF-8")."</pre></body>
</html>";
?>