I have searched religiously here and elsewhere online for resolution to my problem to no avail. I have found many code snippets with samples from javascript to jquery that claim to be able to create and write to a txt or html file, but none of them have worked for me. Here is my issue...
I have a nice little very light php (or html) page that uses a javascript API to record a video, upload it to a server in the cloud and provide me with a token by which I can access that video for playback. It works very nicely to that point.
What I'm trying to do is capture the javascript variable containing the token, then create a new html (or php) file that contains the very simple code using that token to display the video.
Here's the essense of the code...
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//assets.ziggeo.com/css/ziggeo-betajs-player.min.css" />
<script src="//assets.ziggeo.com/js/ziggeo-jquery-json2-betajs-player.min.js">
</script>
<script>
ZiggeoApi.token = "883afacbe59949feae1c9c661d653257";
ZiggeoApi.Events.on("submitted", function (data) {
var token = '<ziggeo ziggeo-video=' + data.video.token + '>';
document.getElementById("output").innerHTML=token;
});
</script>
</head>
<body>
<!-- next line displays the recorder -->
<ziggeo></ziggeo>
<p></p>
<font color=black>
<!-- next line displays the recorded video using the generated token for id -->
<p id='output'></p>
</font>
</body>
</html>
...in the above, after a video is created the ZiggeoApi.Events.on("submitted"... line returns the token in data.video.token. I then am trying to do rather than show the video on the same page in an element identified by "id" is output the code in the head section plus this in the body section of a new html file... '' ...but every javascript effort to do that has failed. No errors, no complaints, and no file.
I tried converting the javascript variable data.video.token to a php variable, because I know I can make php write the file. I have working code for that, except the conversion of the javascript var to a php var isn't working either.
Any help appreciated.
Here are some samples of code I've tried to get the file to write...
<script>
var txtFile = "test.html";
var file = new File(txtFile);
var str = '<ziggeo ziggeo-video=' + data.video.token + '>';
file.open("w"); // open file with write access
file.write(str);
file.close();
</script>
...above didn't work...
<script>
import System.IO;
import System; // Used for getting the date
function Start () {
// Create an instance of StreamWriter to write text to a file.
sw = new StreamWriter("/home4/htlwoadm/public_html/ziggeo/test.txt");
// Add some text to the file.
sw.Write("This is the ");
sw.WriteLine("header for the file.");
sw.WriteLine("-------------------");
// Arbitrary objects can also be written to the file.
sw.Write("The date is: ");
sw.WriteLine(DateTime.Now);
sw.Close();
}
</script>
...above didn't work at all... so didn't try to modify it...
<html><head></head>
<body>
<script>
WriteFile();
</script>
<script>
function WriteFile()
{
var fh = fopen("test.html", 3); // Open the file for writing
if(fh!=-1) // If the file has been successfully opened {
var str = "Some text goes here...";
fwrite(fh, str); // Write the string to a file
fclose(fh); // Close the file
}
}
</script>
</body></html>
...above also didn't work so didn't modify it either...
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
...above works, but can't seem to get the javascript variable up above (data.video.token) to convert to php so haven't modified it either.
Any help appreciated.