I have been searching for hours on how to do this, and am asking for help on what I would like to do.
I would like to dynamically create a file, based on form submitted data using radio buttons as the variable.
For example:
if ($_POST['radio_button_selection'] == "percussion") {
file_put_contents("dynamic_filename.txt", $_POST['radio_button_selection']);
echo "Dynamic filename created";
}
I tried:
if ($_POST['radio_button_selection'] == "percussion") {
file_put_contents("({$_POST['percussion']})", $_POST['radio_button_selection']);
echo "Percussion file created.";
}
But this is not working.
I know I have a missing piece of code to give it the extension, but I don’t know how to do it.
Any help is greatly appreciated.
Thank you.
(EDIT)
Do I need to modify this with PHP code in order to create the file “percussion” as well as write data in the file of the same name?
<input type="radio" value="percussion" name="musictype">Percussion
For example, create the file “percussion.txt” with the word “percussion” in the file.
The code below works and creates the file “percussion.txt” and writes the word “percussion” in the file, but I need the file to be created dynamically while writing to it at the same time.
file_put_contents("percussion.txt", $_POST['musictype'] . "\n", FILE_APPEND);
Bsdnoobz just has it switched.
Make sure the folder you are writing to has write permission.