I have the following code in my index.php page:
// Write the resulting JSON to a text file
var jsontext = $('#code-output').text();
$.ajax({
url: 'writetxt.php',
type: 'POST',
data: { data: jsontext },
success: function(result) {
$('#code-output').hide().fadeIn('slow');
}
});
And this is the contents of writetxt.php:
// Generating a unique filename using the date and time plus a random 4-digit string
$filename = date("YmdHis-") . rand(1337,9001);
// Making the JSON text file
$jsontext = $_POST["data"];
$fp = fopen("jsontxt/" . $filename . ".txt","w");
fwrite($fp,$jsontext);
fclose($fp);
Basically, a new text file is created every time a change is made to the JSON text. How do I access $filename from the index.php file?
Either include the file in the other one
or set it to a session variable
Then the other file