2015-11-04 41 views
0

我在這裏和其他地方在網上搜索宗教信息以解決我的問題無濟於事。我發現了很多代碼片段,包括從javascript到jquery的樣本,聲稱能夠創建並寫入到txt或html文件,但沒有一個適用於我。這是我的問題...javascript中的瀏覽器獨立文件io

我有一個非常輕的php(或html)頁面,使用JavaScript API來錄製視頻,將其上傳到雲端服務器,併爲我提供一個令牌我可以訪問該視頻進行播放。這一點非常好。

我想要做的是捕獲包含令牌的JavaScript變量,然後創建一個新的包含使用該令牌顯示視頻的簡單代碼的HTML(或PHP)文件。

下面的代碼的essense ...

<!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> 

...在上面,視頻創建ZiggeoApi.Events.on後(「提交」 ......行返回令牌data.video.token。然後,我試圖做,而不是顯示在同一頁上的視頻在「id」標識的元素輸出頭部分中的代碼加上這在一個新的HTML文件的正文部分.. '' ...但每一個JavaScript的努力都做了失敗沒有錯誤,沒有投訴,沒有文件

我試圖轉換javasc將變量data.video.token轉換爲一個php變量,因爲我知道我可以讓php寫這個文件。我有工作代碼,除了將JavaScript var轉換爲php var不起作用。

任何幫助表示讚賞。

下面是一些代碼樣本我試着去寫的文件...

<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> 

......上面沒有工作......

<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> 

.. 。以上沒有工作在所有...所以沒有嘗試修改它...

<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> 

...上面也沒有工作,所以沒有任何修改...

<?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); 
?> 

...上述作品,但似乎無法得到JavaScript變量了上述(data.video.token)轉換到PHP等等都沒有任何修改它。

任何幫助表示讚賞。

+0

爲什麼不將token傳遞給你提交的PHP服務器,然後用它做任何你想做的事情? –

+0

我同意鮑比,你最好通過發佈變量到一個PHP頁面,並實際存儲它像一個數據庫的地方。或者,您可以使用像parse.com這樣的服務作爲您的後端來存儲/檢索信息 – DelightedD0D

回答