Ich habe ein HTML-Formular und ein PHP erstellt, die eine TXT-Datei mit der Formulareingabe erstellen und speichern. Es scheint gut zu funktionieren, aber wie kann ich die .txt Datei mit dem "Id" Wert aus dem Formular speichern. Zum Beispiel, wenn der Benutzer eine ID-Nr. 1234 dann sollte die gespeicherte .txt-Datei 1234.txt sein (und nicht output.txt wie in meinem Code).Datei aus PHP-Formular umbenennen
Meine Form:
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<form action="form.php" method="post">
<ol>
<li><label for="email">Email</label>
<input type="text" name="email" id="email"></li>
<li><label for="id">Id</label>
<input type="text" name="id" id="id"></li>
</ol>
</form>
</body>
</html>
und meine php
<?php
ob_start(); // start trapping output
$id = @$_POST['id'];
$email = @$_POST['email'];
?>
<html>
<body>
<p>
Id: <?php echo $id; ?><br>
Email: <?php echo $email; ?>
</p>
</body>
</html>
<?php
$output = ob_get_contents(); // get contents of trapped output
//write to file, e.g.
$newfile="output.txt";
$file = fopen ($newfile, "w");
fwrite($file, $output);
fclose ($file);
ob_end_clean(); // discard trapped output and stop trapping
?>
'$ newfile = $ id.". Txt "sollte funktionieren –