I'm just wondering how can I use a variable name to set a file name in PHP? When I run the following code:
<?php if ($_POST) { $filename = $_POST['firstName']; header("Content-Type: application/txt"); header('Content-Disposition: attachment; filename="$filename.txt"'); echo "Welcome, "; echo $_POST['firstName']. " " . $_POST['lastName']; exit; } else { ?> <form action="" method="post"> First Name: <input type="text" name="firstName" /><br /> Last Name: <input type="text" name="lastName" /><br /> <input type="submit" name="submit" value="Submit me!" /> </form> <?php } ?>
The file name is always " $filename.txt ", but I would like it to be Adam.txt or Brian.txt etc. depending on user input.
Lars source share