I have only the most basic knowledge of web scripting, but i'm trying to learn something. Here what I want to do:
I have a place in a server of my university and have a page there, id like to have some output of what happened in there. So i want to write into a file on click, which places in the same folder as html, also I would like to know how to open file at the end of it (like fstream::app in c++) and get system time.
Here's what I wrote:
<HTML>
<SCRIPT language="JavaScript">
function WriteFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("/net/my path/2011/rija9995/www/Test.txt", true);
fh.WriteLine("Some text goes here...");
fh.Close();
}
</SCRIPT>
<HEAD>
<TITLE>title</TITLE>
</HEAD>
<BODY VLINK=#FF0000 link=#FF0000 alink=#FF0000 bgcolor=#aaaa88 text=#FFFFFF>
<H6>
<TT><CENTER><h2>
<br><br><br><br><br><br><br><br><br><br><br><br><br>
blah blah blah
<button id="button" type="text" onClick="javascript: WriteFile();" />x</button>
</BODY>
</HTML>
Java script cannot have control on server side file system. You need to use a server side language instead ie cgi-scripts/PHP/Java servlets etc. See this for more details.
Solved it, thank you for your answers
<?php
$File = "file.txt";
$Handle = fopen($File, 'a');
$Data = date("Y-m-d H:i:s");
fwrite($Handle, $Data);
fwrite($Handle, " <- ");
fwrite($Handle, $_SERVER['REMOTE_ADDR']);
$Data = "\n";
fwrite($Handle, $Data);
fclose($Handle);
?>
although i hadnt found how to call it upon buttonclick. Any ideas?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.