且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在服务器端机器上创建.txt文件。

更新时间:2023-11-27 22:17:52

基本的是Javascript在CLIENT SIDE上执行。如果您在Javascript中使用ActiveX对象来编写文本文件,那么它(如果确实有效)将文件写入客户端计算机而不是服务器上。



这是服务器端脚本编写的地方。创建一个带有服务器端编码的动态网页,将文件写入服务器上的磁盘。



您可以浏览ASP.NET,PHP和其他Web技术

您可以从客户端调用Ajax请求,并从该服务器端执行方法。该方法将负责创建文本文件。您只需发送用户名或其他内容作为参数。您可以查看链接。介意它ActiveX对象使用它不推荐practive,只有IE可以支持它。


Hi,

ISSUE: I am working on HTML application, an HTML page contains a username, password and Login

button. When i enter the username and password and click Login button, i want to create a text

file and write the username in to the text file on the server side machine.


I have implemented the html page like above issue, but the main problem is when i call the html

page from the server in to the local machine through URL in Internet Explorer. When i enter the

Username and password the .txt file is not created at the server side.

The Page i implemented is like this,

<html>
<title>Mutiara SMART</title>
<SCRIPT language="JavaScript">

function WriteFile()
{
   var username = document.getElementById('txtUserName').value;
   var Scr = new ActiveXObject("Scripting.FileSystemObject");
   var CTF = Scr.CreateTextFile("C:\\DataBuffer", true, true);
   CTF.WriteLine(username);
   CTF.Close();
}

</SCRIPT>
<head>

<link href="admin.css" rel="stylesheet" type="text/css">

</head>
<body>

<center>
<img src = "smart.jpg">
 <table width="350" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="gray" class="entryTable">
        <tr id="entryTableHeader">
         <td>:: Login ::</td>
        </tr>
        <tr>
         <td class="contentArea">

    <table width="100%" border="0" cellpadding="2" cellspacing="1" class="text">
           <tr align="center">
            <td colspan="3">&nbsp;</td>
           </tr>
           <tr class="text">
            <td width="100" align="right">Username </td>
            <td width="10" align="center">:</td>
            <td><input name="txtUserName" type="text" class="box" id="txtUserName" value="" size="30" maxlength="100"></td>
           </tr>
           <tr>
            <td width="100" align="right">Password </td>
            <td width="10" align="center">:</td>
            <td><input name="txtPassword" type="password" class="box" id="txtPassword" value="" size="30"></td>
           </tr>
           <tr>
            <td colspan="2">&nbsp;</td>
            <td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a onClick="javascript: CreateFile();">Login</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
           </tr>
          </table>

</center>

</body>

</html>




can anyone give an idea on how to create .txt file on server side.

Thank you in Advance.

The basic thing is that the Javascript executes on CLIENT SIDE. If you are using ActiveX objects in Javascript to write the text file , then it will ( if it really works) write the file to client machine and not on the server.

This is where the server side scripting comes into picture. Create a dynamic webpage with server side coding where it writes a file to the disk on server.

You can explore ASP.NET, PHP and other web technologies


You can call Ajax request from client side and from that server side method will execute. That method will responsible to create text file. You just send username or other things as argument. You can check the Link. Mind it ActiveX object use it not recommended practive, only IE can support it.