I have created a script that outputs a string containing XML, Json or text. Now I want the visitor to be able to save it, but I don't want to save it on the server. It should only be saved by the visitor after the output content is generated.
Here is what I did:
if(isset($_POST['submit_down'])){
$string = $_POST['result_text'];
$type = $_POST['result_type'];
if($type == "json") {
header ("Content-Type: application/json");
header ("Content-disposition: attachment; filename=names.json");
} elseif($type == "xml") {
header ("Content-Type: application/xml");
header ("Content-disposition: attachment; filename=names.xml");
} elseif($type == "text"){
header ("Content-Type: text/plain");
header ("Content-disposition: attachment; filename=names.txt");
}
echo $string;
exit();
}
$string
contains the content for the file.
The code I posted only displays the code in browser instead of saving it. What could be the problem?