Reputation: 23
I've got a list of music artists set up as a html page with check boxes so a user can chose what they want me to load on their mp3 player. they check and then click a submit button that executes this...
<?php
$name = $_GET['artist'];
foreach ($name as $artist){
echo $artist."<br />";
}
?>
All good. Returns a page of their selections. I would like to provide a button on this results page that, when clicked, saves a file of what is on this results page to the server dir where all of this lives so that file can be emailed later via a cron job to me. can anyone tell me the simplest way to do this? My problem is that most examples i have found want to handle the form data directly. I just want to save the actual text of the finished page line for line. I think this must be simple but it eludes me. thanks for your help!
Upvotes: 0
Views: 81
Reputation: 163272
The form data is sent in fielded form to the server. It is not sent as a text file. You should generate this file server-side.
Since you will be working with this data later, I suggest using JSON-encoding. It will allow you to read this text file easily later on.
file_put_contents('yourfile.json', json_encode($_GET));
Alternatively, you can easily loop through what was posted and write lines to whatever you want:
foreach ($_GET as $key => $value) {
echo $key, ': ', $value; // Change this line to write wherever in whatever format
}
Upvotes: 1